winform中的whileloop导致应用程序崩溃!为什么? [英] whileloop in winform cause app to crash ! why ?
问题描述
你好朋友,
由于某些原因我在winform中执行这段代码时它会立即崩溃应用程序。
基本上我正在尝试为基于客户端/服务器的应用程序管理线程池。
while(true)
{
while(!client.Pending())
{
Thread.Sleep(1000);
}
ConnectionThread newconnection = new
ConnectionThread();
newconnection.threadListener = this.client;
ThreadPool.QueueUserWorkItem(新
WaitCallback(newconnection.HandleConnection) ); b / b
调试后,它一进入while循环就会崩溃。
任何智慧的碎屑都赞赏
thankyou
Tom
Hello friends,
for some reason when I execute this piece of code in a winform it
immediately crashes the app.
baseically I''m trying to manage a thread pool for a client/server based app.
while(true)
{
while (!client.Pending())
{
Thread.Sleep(1000);
}
ConnectionThread newconnection = new
ConnectionThread();
newconnection.threadListener = this.client;
ThreadPool.QueueUserWorkItem(new
WaitCallback(newconnection.HandleConnection));
}
after debugging it seems to crash as soon as it enters the while loop.
any crumbs of wisdom is appreciated
thankyou
Tom
推荐答案
while循环是一个无限循环。
while(true)
要求你使用break关键字手动取消循环;
while(true)
{
Something();
if(IsFinished())
{
break;
}
}
while(true)有点受欢迎。
就个人而言,我从不使用这样的声明,除非我真的必须
因为我不认为它很干净。
相反,我在while语句中形成一个条件。
while(! IsFinished())
{
Something();
}
-
问候,
DennisJDMyrén
Oslo Kodebureau
" Tom" <到******** @ optushome.com.au>在消息中写道
news:41 ********************** @ news.optusnet.com.au ...
The while loop is an infinite loop.
while (true)
requires you to manually cancel the loop by using break keyword;
while (true)
{
Something();
if (IsFinished())
{
break;
}
}
The while (true) is somewhat popular.
Personally, i never use a such statement unless i really have to
because i dont think it is very clean.
Instead, i form a condition in the while statement.
while (! IsFinished())
{
Something();
}
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Tom" <to********@optushome.com.au> wrote in message
news:41**********************@news.optusnet.com.au ...
朋友们好,
由于某些原因,当我在winform中执行这段代码时,
会立即崩溃应用程序。
基本上我是'我试图管理基于
app的客户端/服务器的线程池。
while(true)
while(!client。等待())
Thread.Sleep(1000);
}
ConnectionThread newconnection = new
ConnectionThread();
newconnection.threadListener =
this.client;
ThreadPool.QueueUserWorkItem(新
WaitCallback(newconnection.HandleConnection) );
调试后,一旦进入while循环,它似乎就会崩溃。
任何智慧的碎屑都会被赞赏
thankyou
>
Tom
Hello friends,
for some reason when I execute this piece of code in a winform it
immediately crashes the app.
baseically I''m trying to manage a thread pool for a client/server based app.
while(true)
{
while (!client.Pending())
{
Thread.Sleep(1000);
}
ConnectionThread newconnection = new
ConnectionThread();
newconnection.threadListener = this.client;
ThreadPool.QueueUserWorkItem(new
WaitCallback(newconnection.HandleConnection));
}
after debugging it seems to crash as soon as it enters the while loop.
any crumbs of wisdom is appreciated
thankyou
Tom
while循环是一个无限循环。
while(true)
要求你使用break关键字手动取消循环;
while(true)
{
Something();
if(IsFinished())
{
break;
}
}
while(true)有点受欢迎。
就个人而言,我从不使用这样的声明,除非我真的必须
因为我不认为它很干净。
相反,我在while语句中形成一个条件。
while(! IsFinished())
{
Something();
}
-
问候,
DennisJDMyrén
Oslo Kodebureau
" Tom" <到******** @ optushome.com.au>在消息中写道
news:41 ********************** @ news.optusnet.com.au ...
The while loop is an infinite loop.
while (true)
requires you to manually cancel the loop by using break keyword;
while (true)
{
Something();
if (IsFinished())
{
break;
}
}
The while (true) is somewhat popular.
Personally, i never use a such statement unless i really have to
because i dont think it is very clean.
Instead, i form a condition in the while statement.
while (! IsFinished())
{
Something();
}
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Tom" <to********@optushome.com.au> wrote in message
news:41**********************@news.optusnet.com.au ...
朋友们好,
由于某些原因,当我在winform中执行这段代码时,
会立即崩溃应用程序。
基本上我是'我试图管理基于
app的客户端/服务器的线程池。
while(true)
while(!client。等待())
Thread.Sleep(1000);
}
ConnectionThread newconnection = new
ConnectionThread();
newconnection.threadListener =
this.client;
ThreadPool.QueueUserWorkItem(新
WaitCallback(newconnection.HandleConnection) );
调试后,一旦进入while循环,它似乎就会崩溃。
任何智慧的碎屑都会被赞赏
thankyou
>
Tom
Hello friends,
for some reason when I execute this piece of code in a winform it
immediately crashes the app.
baseically I''m trying to manage a thread pool for a client/server based app.
while(true)
{
while (!client.Pending())
{
Thread.Sleep(1000);
}
ConnectionThread newconnection = new
ConnectionThread();
newconnection.threadListener = this.client;
ThreadPool.QueueUserWorkItem(new
WaitCallback(newconnection.HandleConnection));
}
after debugging it seems to crash as soon as it enters the while loop.
any crumbs of wisdom is appreciated
thankyou
Tom
Tom,
你有什么例外得到些什么?另外,在不知道由于线程池线程被调用而被调用回来的
代码,这很难说。
-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com
汤姆 <到******** @ optushome.com.au>在消息中写道
news:41 ********************** @ news.optusnet.com.au ...
Tom,
What is the exception that you are getting? Also, without knowing the
code that is called back into as a result of the thread pool thread being
called, it''s hard to tell.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Tom" <to********@optushome.com.au> wrote in message
news:41**********************@news.optusnet.com.au ...
朋友们好,
由于某些原因,当我在winform中执行这段代码时,
会立即崩溃应用程序。
基本上我是'我试图为基于客户端/服务器的应用程序管理一个线程池。
while(true)
(!client.Pending())
Thread.Sleep(1000);
}
ConnectionThread newconnection = new
ConnectionThread();
newconnection.threadListener = this.client;
ThreadPool.QueueUserWorkItem(新
WaitCallback( newconnection.HandleConnection));
调试后,一旦进入while循环,它似乎就会崩溃。
任何智慧的碎屑都会被赞赏
thankyou
>
Tom
Hello friends,
for some reason when I execute this piece of code in a winform it
immediately crashes the app.
baseically I''m trying to manage a thread pool for a client/server based
app.
while(true)
{
while (!client.Pending())
{
Thread.Sleep(1000);
}
ConnectionThread newconnection = new
ConnectionThread();
newconnection.threadListener = this.client;
ThreadPool.QueueUserWorkItem(new
WaitCallback(newconnection.HandleConnection));
}
after debugging it seems to crash as soon as it enters the while loop.
any crumbs of wisdom is appreciated
thankyou
Tom
这篇关于winform中的whileloop导致应用程序崩溃!为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!