输入字符串的格式不正确怎么解决啊 #C

wy3792 2010-07-03 09:22:30
未处理 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);
}
}
...全文
961 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wy3792 2010-07-03
  • 打赏
  • 举报
回复
3Q
完成了 十分感谢
兔子-顾问 2010-07-03
  • 打赏
  • 举报
回复
if(secondWatch.ElapsedMilliseconds/1000==int.Parse(textBoxTimeInterval.Text))---这一行报错
----------------------------------------
修改为:
int nTest;
if(!int.TryParse(textBoxTimeInterval.Text,out nTest)) return;
if(secondWatch.ElapsedMilliseconds/1000==nTest)
wuyq11 2010-07-03
  • 打赏
  • 举报
回复
int.TryParse判断
textBoxTimeInterval.Text单步检查值
wy3792 2010-07-03
  • 打赏
  • 举报
回复
本人菜鸟。。。可以说详细些不 别人的程序我在调试 是把
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();
之前么
编程有钱人了 2010-07-03
  • 打赏
  • 举报
回复

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

编程有钱人了 2010-07-03
  • 打赏
  • 举报
回复

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

111,076

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧