473,811 Members | 3,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mutithreading in a Winforms app with CDO

I have written an application that launches approximately 150 threads with
Thread.ThreadSt art()

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 Appilcation.Exi t() 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
Mar 20 '06 #1
2 2084
Please use Join on all thread before closing the main thread.
Put the references to all the threads in e.g an arraylist and run through
the list and call the join() method on all the threads.
Make sure you don't close any threads explicitly with any close statements
on the thread. Let the threads die on it's own.

Tell us how things are going.

Regards,
Lars-Inge Tønnessen
Mar 20 '06 #2
Thanks for your feedback.

I did have an ArrayList of objects in my app, and had stored away the thread
object when it was launched, so
it was easy to add the following in my btnExit_click object:
for (int x = 0; x < mboxList.Count; x++)
{
myTestMailbox y = (myTestMailbox) mboxList[x];
System.Diagnost ics.Debug.Write Line("Joining thread : " +
x.ToString("00" ));
y.theThread.Joi n();
}

On the first pass through the loop, the application stops on thread.Join().
After about a minute or so I get the following error:

----------------------------------------------
ContextSwitchDe adlock was detected
Message: The CLR has been unable to transition from COM context 0x1a1e90 to
COM context 0x1a27e8 for 60 seconds.
The thread that owns the destination context/apartment is most likely either
doing a non pumping wait or processing
a very long running operation without pumping Windows messages. This
situation generally has a negative performance
impact and may even lead to the application becoming non responsive or
memory usage accumulating continually over time.

To avoid this problem, all single threaded apartment (STA) threads should
use pumping wait primitives
(such as CoWaitForMultip leHandles) and routinely pump messages during long
running operations.
------------------------------------------------

The method that is running in each thread does not do anything specific to
terminate the thread, other than falling out of the While() loop
and calling the CDO Logoff() method to log off of the mailbox.

If you have any ideas what the problem could be I would appreciate your
feedback.

Thanks again

Steve


"Lars-Inge Tønnessen (VJ# MVP)" <http://emailme.larsing e.com> wrote in
message news:eu******** ********@TK2MSF TNGP09.phx.gbl. ..
Please use Join on all thread before closing the main thread.
Put the references to all the threads in e.g an arraylist and run through
the list and call the join() method on all the threads.
Make sure you don't close any threads explicitly with any close statements
on the thread. Let the threads die on it's own.

Tell us how things are going.

Regards,
Lars-Inge Tønnessen

Mar 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1445
by: Alan Partridge | last post by:
I have an app with both a webforms and winforms front end. When I change the web.config file, eventually IIS\ASP.NET pick up the changes and all is well. With the WinForms GUI - when I change the .config file, I need a way to force the AppDomain to reload the new config settings. This doesn't need to be automatic cause I can control when the config file is updated. Does anyone know how to force a reload of a new config
10
2418
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ComboBox.SelectedValue = db_value; If the db_value was not included in the ComboBox value list the ComboBox.SelectedIndex used to return -1, Now the very same code is
4
3739
by: Elhanan | last post by:
hi.. all a client of ours is considering to move from a dos application to windows desktop application. the application is for traveling agency, the database is rather large. their current database for other application is SQL-SERVER. they have 12 users.
0
1386
by: Shamil Salakhetdinov | last post by:
Hi All, Have anybody seen somewhere techniques like the one described here: Automating Windows Applications http://www.thecodeproject.com/com/automatingwindowsapps.asp but for managed WinForms application? Basically what is needed:
5
4101
by: Segfahlt | last post by:
I need a little help here please. I have 2 win forms user controls in 2 different projects that I'm hosting in 2 different virtual directories. The controls have been test and operate okay in both projects. Both controls(dlls) have been signed using SN.exe and I've set up the appropriate .Net assembly permissions using those Strong Names The DLL's have been copied to the /bin directory in both web virtual directories.
1
8562
by: Pieter | last post by:
Hi, In my application VB.NET 2005 application I placed a ReportViewer, and link it to a server-report: Me.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote Me.ReportViewer1.ServerReport.ReportPath = "/myproject/DemandeDeCotation" Me.ReportViewer1.ServerReport.ReportServerUrl = New System.Uri("http://myserver/reportserver2005", System.UriKind.Absolute)
4
3942
by: 3Cooks | last post by:
I have a windows application written in Visual Basic 6.0 that is going to be redeveloped in dotNET. We are trying to decide if we should deploy using Webforms or Winforms and I need advice from someone who is not on my team. The VB 6.0 application is used by approximately 100 users. All users reside in-house. There is an existing external website that will use some of the same components but the two applications are separate. The...
0
1657
by: netflex | last post by:
Working on a handed off C# project and pretty much my third time dipping into C#. In my solution file, I have a collection of .resx files in their own folder, several .cs files, and my winforms .cs files. From what I understand the .resx files house embedded resources, such as images and buttons texts. When I open up my winforms however there is nothing there! When I open up my winforms code behind, I see code such as: this.$ = new...
5
3831
by: brian.wilson4 | last post by:
Our group is currently comparing winforms vs webforms.....app is Corp LAN based - we have control of desktops.....Below is pros and cons list we have come up with - if anything strikes you as untrue or you would like to add - please comment - thanks..... Rich Client PROS 1. User experience (* indicates feasible on web with AJAX) - a. Single, unified application experience b. Windows/Office-like look and feel - i.Tabs - drag and drop...
23
4575
by: raylopez99 | last post by:
Here I am learning WinForms and two months into it I learn there's a WPF API that is coming out. Is this WPF out yet, and is it a threat to WinForms, in the sense that all the library routines I memorize and/ or familiarize myself in WinForms will disappear in WPF? I did note in one early version of C#, the non-generic "ArrayList" was replaced by the generic and template <based List, but that kind of change is not a big deal. If WPF...
0
9730
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10403
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4341
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.