Re: PInvoke threading issue

From: Peter Huang (v-phuang_at_online.microsoft.com)
Date: 10/06/04


Date: Wed, 06 Oct 2004 08:56:36 GMT

Hi,

One possibility is that if the third-party dll called a COM object which is
main threaded that is to say we did not specified the thread model for the
COM Object. In this way, the COM object will be created and running on the
main thread, i.e. the main UI thread which may cause the main UI form
thread blocked. Usually the main thread is the first thread in the process.

So I think you may try to change your code as below.
<code snippet>
[STAThread]
static void Main()
{
                //run the winform in the second thread.
        Thread th = new Thread(new ThreadStart(ThreadProc));
        th.Start();

               //Run the P/Inovke code in the main thread, try to replace
the three code lines below
        TestCOMP.COMPClass tcc = new TestCOMP.COMPClass();
        tcc.SleepVB(1000);
}
public static void ThreadProc()
{
        Application.Run(new Form1());
}
</code snippet>

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.



Relevant Pages

  • Pull method for sqlceremotedataaccess
    ... catch (SqlCeException ce) ... private static void CreateDatabase() ... // Pull down the authors table from the pubs database on the remote ... internetUrl in the code snippet without any error ...
    (microsoft.public.sqlserver.ce)
  • pull method
    ... catch (SqlCeException ce) ... private static void CreateDatabase() ... // Pull down the authors table from the pubs database on the remote ... internetUrl in the code snippet without any error ...
    (microsoft.public.sqlserver.replication)
  • RE: About send a string to a C# app
    ... Checkout this code snippet: ... static void Main(stringargs) ...
    (microsoft.public.dotnet.languages.csharp)

Loading