C#Winforms app中的线程和CDO问题 [英] Problems with Threading and CDO in C# Winforms app

查看:100
本文介绍了C#Winforms app中的线程和CDO问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个winforms应用程序,用

发布大约150个b $ b线程.Thread.ThreadStart()


每个帖子使用CDO 1.21登录到另一个Exchange邮箱,并且
发送/接收大量邮件消息,通过使用Queue对象向UI线程报告
。当收到预期的所有消息都已收到

时,每个线程都会向UI发送最终更新,并且方法

应该退出,这应该终止该线程。


尽管我正在与某些邮箱上的

Outlook安全性对话框进行战斗,但大部分都运行良好。


当所有线程完成工作后,UI上的退出按钮启用了
。当我单击它时,将调用Application.Exit()函数,并且

UI消失,但应用程序继续运行。在调试

环境中,我最终得到一个线程死锁消息。此时,

应该只有一个线程在运行。


我读过大量关于线程的文章并检查了很多样本​​并且

看不出我编写这个应用程序的方式有什么问题。


如果有人遇到过这种类型的问题,或者对我的怎样建议

可以尝试解决这个问题,我将不胜感激。是否有可能CDO

对象是问题的一部分?


提前谢谢


Steve


解决方案

请参阅我之前的帖子。你从我的帖子中得到了什么吗?


问候,

Lars-Inge T?nnessen


< blockquote>

您确定所有线程都已进入STA吗?这是

CDO所必需的。

请注意,我认为没有理由拥有150个线程,并且所有报告都返回给UI的
线程,这是比赛的一部分还是什么?你只是在为线程堆栈浪费了150亿美元的内存而浪费了大量的CPU资源

只是为了切换线程,这只会减慢整个应用程序的速度。 w $> b $ b Willy。


Steve Smith < ST *********** @ shaw.ca>在消息中写道

新闻:uI ************** @ TK2MSFTNGP09.phx.gbl ...

|我写了一个winforms应用程序启动大约150

|线程与

| Thread.ThreadStart()

|

|每个线程使用CDO 1.21登录到不同的Exchange邮箱和

|发送/接收一些邮件消息,向UI线程报告

|通过使用Queue对象。当所有预期的消息

都有

|收到后,每个帖子都会向UI和方法发送最终更新

|应该退出,这应该终止线程。

|

|一切都运作良好,虽然我正在与

进行战斗

|某些邮箱上的Outlook安全性对话框。

|

|当所有线程完成工作后,UI上的Exit按钮为

|启用。当我点击它时,调用Application.Exit()函数,并且



| UI消失,但应用程序继续运行。在调试中

|环境最终我得到一个线程死锁消息。此时,

那里

|应该只运行一个线程。

|

|我已经阅读了很多关于线程的文章,并检查了很多样本​​和

|我编写这个应用程序的方式看不出有什么问题。

|

|如果有人遇到过这种类型的问题,或者对如何建议怎么说?

|可能会试图解决这个问题,我将不胜感激。是否有可能CDO

|对象是问题的一部分吗?

|

|在此先感谢

|

|史蒂夫

|

|

|

|


< blockquote>您是否将线程设置为后台线程?通过将它们设置为

背景CLR在

前景线程终止时结束后台线程的进程。

I have written a winforms application that launches approximately 150
threads with
Thread.ThreadStart()

Each thread uses CDO 1.21 to logon to a different Exchange mailbox and
send/receive a number of mail messages, reporting back to the UI thread
through the use of a Queue object. When all messages that are expected have
been received, each thread sends a final update to the UI and the method
should exit, which should terminate the thread.

Everything works well for the most part, although I am doing battle with the
Outlook Security dialog on some mailboxes.

When all threads have completed their work, the Exit button on the UI is
enabled. When I click it, the Application.Exit() function is called, and the
UI disappears, but the application continues to run. In the debug
environment eventually I get a thread deadlock message. At this point, there
should only be one thread running.

I have read numerous articles on threading and examined many samples and
cannot see anything wrong with the way I have coded this application.

If anyone has experienced this type of problem, or has a suggestion on how I
could try to nail this down, I would appreciate it. Is it possible the CDO
object is part of the problem?

Thanks in advance

Steve


解决方案

Please see my previous post. Do you get anything out of my post?

Regards,
Lars-Inge T?nnessen



Are you sure all of your threads have entered the STA? This is required by
CDO.
Note that I see no reason at all to have 150 threads, and all reporting back
to the UI thread, is this part of a contest or what? You are just wasting
150MB of memory for the thread stacks and you waste a lot of CPU resources
just to switch the threads which will just slow down the whole application.
Willy.

"Steve Smith" <st***********@shaw.ca> wrote in message
news:uI**************@TK2MSFTNGP09.phx.gbl...
|I have written a winforms application that launches approximately 150
| threads with
| Thread.ThreadStart()
|
| Each thread uses CDO 1.21 to logon to a different Exchange mailbox and
| send/receive a number of mail messages, reporting back to the UI thread
| through the use of a Queue object. When all messages that are expected
have
| been received, each thread sends a final update to the UI and the method
| should exit, which should terminate the thread.
|
| Everything works well for the most part, although I am doing battle with
the
| Outlook Security dialog on some mailboxes.
|
| When all threads have completed their work, the Exit button on the UI is
| enabled. When I click it, the Application.Exit() function is called, and
the
| UI disappears, but the application continues to run. In the debug
| environment eventually I get a thread deadlock message. At this point,
there
| should only be one thread running.
|
| I have read numerous articles on threading and examined many samples and
| cannot see anything wrong with the way I have coded this application.
|
| If anyone has experienced this type of problem, or has a suggestion on how
I
| could try to nail this down, I would appreciate it. Is it possible the CDO
| object is part of the problem?
|
| Thanks in advance
|
| Steve
|
|
|
|


Have you set the threads as Background threads? By setting them to
Background CLR ends the process of the background threads when
foreground threads are terminated.


这篇关于C#Winforms app中的线程和CDO问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆