未处理 System.FormatException
  Message="输入字符串的格式不正确。"
  Source="mscorlib"
  StackTrace:
       在 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
       在 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
       在 System.Int32.Parse(String s)
       在 P2PExample.FormP2P.timerSecond_Tick(Object sender, EventArgs e) 位置 G:\网络通信\P2PExample\P2PExample\FormP2P.cs:行号 279
       在 System.Windows.Forms.Timer.OnTick(EventArgs e)
       在 System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 P2PExample.Program.Main() 位置 G:\网络通信\P2PExample\P2PExample\Program.cs:行号 18
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: 代码如下:
 private void timerSecond_Tick(object sender, EventArgs e)
        {
          if(secondWatch.ElapsedMilliseconds/1000==int.Parse(textBoxTimeInterval.Text))---这一行报错
            {
                textBoxTimerStatus.Text = "刷新";
                timerSecond.Stop();
                secondWatch.Reset();
                for (int i = 0; i < listViewMyFriend.Items.Count; i++)
                {
                    string remoteIpString = listViewMyFriend.Items[i].SubItems[0].Text;
                    string remotePortString = listViewMyFriend.Items[i].SubItems[1].Text;
                    SendMessage(remoteIpString, remotePortString, "check", "看看你还在没?");
                }
                timerSecond.Start();
                secondWatch.Start();
            }
            else
            {
                textBoxTimerStatus.Text = string.Format("{0}", secondWatch.ElapsedMilliseconds / 1000);
            }
        }

解决方案 »

  1.   


    int ii=0;
    if(!intTryParse(textBoxTimeInterval.Text,ii))
    {
    //message.box("必须是数字");
    }
      

  2.   


    int ii=0; if(!intTryParse(textBoxTimeInterval.Text,ii))
     { 
    message.box("必须是数字");
    return
     }
    //然后再进行下面的操作
      

  3.   

    本人菜鸟可以说详细些不   别人的程序我在调试    是把
    int ii=0; if(!intTryParse(textBoxTimeInterval.Text,ii))
     { 
    message.box("必须是数字");
    return
     }
    加在
    private void timerSecond_Tick(object sender, EventArgs e)
      {
      if(secondWatch.ElapsedMilliseconds/1000==int.Parse(textBoxTimeInterval.Text))---这一行报错
      {
      textBoxTimerStatus.Text = "刷新";
      timerSecond.Stop();
      secondWatch.Reset();
    之前么
      

  4.   

    int.TryParse判断
    textBoxTimeInterval.Text单步检查值
      

  5.   

    if(secondWatch.ElapsedMilliseconds/1000==int.Parse(textBoxTimeInterval.Text))---这一行报错
    ----------------------------------------
    修改为:
    int nTest;
    if(!int.TryParse(textBoxTimeInterval.Text,out nTest)) return;
    if(secondWatch.ElapsedMilliseconds/1000==nTest)