another workaround is to set the thread's ApartmentState to STA, that means
to enter the follwing line over the myThreadX.Start(); line;

myThreadX.ApartmentState = ApartmentState.STA;

this works most of the time, sometimes a System.ArgumentException exception
is thrown but the programm doesn't block, so it isn't an optimal workaround
but sometimes better as to add hundreds of Dispose calls in an already
finished code.

- stefan



then it work most of the time, sometimes


On Tue, 26 Mar 2002 10:06:49 -0800, Ron Jacobs <[EMAIL PROTECTED]>
wrote:

>You can workaround this by calling dispose on the object that your
>factory created.
>
>class TestThreadHandler
>{
>        public string threadName;
>        public void HandleThread()
>        {
>                TransObjFactory fac = new TransObjFactory();
>                for(int i = 0; i < 500; i++)
>                {
>                        TransObj t = fac.NewTransObj();
>                        t.Dispose();
>                        Console.WriteLine("Thread " + threadName + ", i=
>" +                             i.ToString());
>                }
>                Console.WriteLine("Thread " + threadName + "
>finished.");
>        }
>}
>
>We are aware of this problem but for now you should workaround this
>issue by calling dispose.
>
>-----Original Message-----
>From: Stefan Hainzer [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, March 26, 2002 6:40 AM
>To: [EMAIL PROTECTED]
>Subject: [DOTNET] ServicedComponent bug in final .NET?
>
>hello,
>
>I think that I have found a bug in the .NET final which didn't appear
>in the .NET Beta 2.
>
>The following situation:
>
>You have a factory object which creates serviced component objects.
>You use one factory to create 500 objects.
>You do that parallel in 3 different threads (each thread has its
>own factory).
>
>The .Net final version stops after a few hundret (or more) successfully
>created objects without an exception, it still hangs.
>The .Net beta 2 version does the job without problems.
>
>I tried the example on 3 diffrent computers:
>WIN 2000 with .NET beta 2 (OK)
>WIN 2000 with .NET final (fault)
>WIN XP with .NET final and .NET SP1 (fault).
>
>The example code:
>
>using System;
>using System.Threading;
>using System.EnterpriseServices;
>
>namespace ConsoleApplication2
>{
>[Transaction(TransactionOption.Required)]
>public class TransObj : ServicedComponent
>{
> public TransObj():base()
> {}
>}
>
>[Transaction(TransactionOption.Supported)]
>public class TransObjFactory : ServicedComponent
>{
> public TransObjFactory():base()
> {}
>
> public TransObj NewTransObj()
> {
>  return new TransObj();
> }
>}
>
>class TestThreadHandler
>{
> public string threadName;
> public void HandleThread()
> {
> TransObjFactory fac = new TransObjFactory();
> for(int i = 0; i < 500; i++)
> {
> fac.NewTransObj();
> Console.WriteLine("Thread " + threadName + ", i= " + i.ToString());
> }
>        Console.WriteLine("Thread " + threadName + " finished.");
>}
>}
>
>
>class Class1
>{
>static void Main(string[] args)
>{
>TestThreadHandler handler = new TestThreadHandler();
>handler.threadName = "Thread 1";
>ThreadStart myThreadStart = new ThreadStart(handler.HandleThread);
>Thread myThread = new Thread(myThreadStart);
>myThread.Start();
>
>TestThreadHandler handler1 = new TestThreadHandler();
>handler1.threadName = "Thread 2";
>ThreadStart myThreadStart1 = new ThreadStart(handler1.HandleThread);
>Thread myThread1 = new Thread(myThreadStart1);
>myThread1.Start();
>
>TestThreadHandler handler2 = new TestThreadHandler();
>handler2.threadName = "Thread 3";
>ThreadStart myThreadStart2 = new ThreadStart(handler2.HandleThread);
>Thread myThread2 = new Thread(myThreadStart2);
>myThread2.Start();
>
>System.Console.ReadLine();
>}
>}
>}
>
>
>Has anybody an idea how to explain this behaviour?
>I'm thankfully for any suggestion (I have this problem
>in an productive environment),
>
>regards
>
>stefan
>
>You can read messages from the DOTNET archive, unsubscribe from DOTNET,
>or
>subscribe to other DevelopMentor lists at http://discuss.develop.com.
>
>You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
>subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to