For Programmers: Free Programming Magazines  


Home > Archive > C# > September 2005 > Creating control in a threadpool thread slows down Excel startup ( bug in framework?)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Creating control in a threadpool thread slows down Excel startup ( bug in framework?)
kjartan.storli@gmail.com

2005-09-30, 6:58 pm

Hi,


Below is a small application which recreates a problem we found in one
of our
programs.
When this application is run it takes almost a minute to start Excel if
you double-click on an Excel file. It seems like it has the same effect
on other programs which is started with DDE commands.

class ThreadPoolTest
{
static void Main(string[] args)
{
System.Threading.TimerCallback ts = new
System.Threading.TimerCallback(CallbackTarget);
System.Threading.Timer t = new System.Threading.Timer(ts , null , 0 ,
3000);
System.Windows.Forms.Application.Run();
}

private static void CallbackTarget(object o)
{
System.Windows.Forms.Control c = new System.Windows.Forms.Control();
c.CreateControl();
}
}

Notice that during program execution the CallbackTarget function is
called in a threadpool thread.
If you try to start Excel by double clicking on an Excel file while the
app is running, it takes a long time before Excel is loaded ( sometimes
over a minute).

I understand that creating a control on a threadpool thread might be a
bit strange, but I haven't understood *why* this affects other
programs.
Can someone explain this behavour, or is it a bug in the .Net framework?

Roland Kaufmann

2005-09-30, 6:58 pm

It will probably block global DDE broadcast messages by not servicing
the message pump in the thread. Threadpool threads are by nature
started in a multi-threaded apartement (MTA), and thus no message pump
is provided by the framework.

The reason why Excel does not show up in the task list is because it is
Explorer that sends the broadcast (to find out if Excel is already
started).

Related cases in this respect is Q181949 in MSKB "BUG: DCOM95 MTA
Clients May Block Broadcast DDE Messages"
<http://support.microsoft.com/?id=181949> and Q136218 "BUG: DdeConnect
Never Returns" <http://support.microsoft.com/?id=136218>.

One can also observe the same behavior in the following program which
creates a secondary thread with a top-level window and then hangs the
thread.

using System;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;

class SonOfKiller {
public static void Main( String[] args ) {
new Thread(new ThreadStart(OnThreadStart)).Start();
Application.Run();
}

private static void OnThreadStart() {
Control c = new Control();
c.CreateControl();
Process.GetCurrentProcess().WaitForExit();
}
}

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com