threading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Avi Kadosh

    #1

    threading

    hi all

    I am new to Csharp

    I tried the following code

    using System;

    using System.Threadin g;

    using System.Messagin g;


    namespace ConsoleApplicat ion3

    {

    /// <summary>

    /// Summary description for Class1.

    /// </summary>

    ///

    class QueueWorker

    {


    private MessageQueue MQueue;

    private int index;

    public QueueWorker(int ix)

    {

    index = ix;

    }

    public void CreateQueue()

    {

    if (!MessageQueue. Exists(".\\priv ate$\\" + index ))

    {

    MQueue = MessageQueue.Cr eate(".\\privat e$\\" + index , false);

    }

    else

    {

    MQueue = new MessageQueue(". \\private$\\" + index,true);

    }

    MQueue.Formatte r = new ActiveXMessageF ormatter();

    MQueue.ReceiveC ompleted += new
    ReceiveComplete dEventHandler(M yReceiveComplet ed);

    MQueue.BeginRec eive() ;

    Console.WriteLi ne("Start Reciving on Queue " + index);

    Thread.CurrentT hread.Name = "My Queue Hadle Thread " + index;



    }

    private void MyReceiveComple ted(Object source,

    ReceiveComplete dEventArgs asyncResult)

    {

    // Connect to the queue.

    MessageQueue mq = (MessageQueue)s ource;

    // End the asynchronous Receive operation.

    Message m = mq.EndReceive(a syncResult.Asyn cResult);


    // Display message information on the screen.

    //Console.WriteLi ne("Message: " + (string)m.Body) ;

    try

    {

    Console.WriteLi ne((string)m.Bo dy);

    }

    catch

    {

    }

    // Restart the asynchronous Receive operation.

    mq.BeginReceive ();


    return;

    }

    }

    class Class1

    {

    /// <summary>

    /// The main entry point for the application.

    /// </summary>

    static void Main(string[] args)

    {

    QueueWorker[] a = new QueueWorker[30] ;

    for(int i=0;i<30;i++)

    {

    a[i] = new QueueWorker(i) ;

    a[i].CreateQueue;

    }

    while(true)

    {

    System.Threadin g.Thread.Sleep( 10000);

    }

    //

    // TODO: Add code to start application here

    //

    }

    }

    }



    it is working fine the problem is when I tried to change it to multithreaded
    application (each queue worker is runing in it's own queue)

    it create the thread but stop reciving events ... any ideas?



    using System;

    using System.Threadin g;

    using System.Messagin g;


    namespace ConsoleApplicat ion3

    {

    /// <summary>

    /// Summary description for Class1.

    /// </summary>

    ///

    class QueueWorker

    {


    private MessageQueue MQueue;

    private int index;

    public QueueWorker(int ix)

    {

    index = ix;

    Thread myThread = new Thread(new ThreadStart(thi s.CreateQueue)) ;

    myThread.Start( );

    }

    public void CreateQueue()

    {

    if (!MessageQueue. Exists(".\\priv ate$\\" + index ))

    {

    MQueue = MessageQueue.Cr eate(".\\privat e$\\" + index , false);

    }

    else

    {

    MQueue = new MessageQueue(". \\private$\\" + index,true);

    }

    MQueue.Formatte r = new ActiveXMessageF ormatter();

    MQueue.ReceiveC ompleted += new
    ReceiveComplete dEventHandler(M yReceiveComplet ed);

    MQueue.BeginRec eive() ;

    Console.WriteLi ne("Start Reciving on Queue " + index);

    Thread.CurrentT hread.Name = "My Queue Hadle Thread " + index;



    }

    private void MyReceiveComple ted(Object source,

    ReceiveComplete dEventArgs asyncResult)

    {

    // Connect to the queue.

    MessageQueue mq = (MessageQueue)s ource;

    // End the asynchronous Receive operation.

    Message m = mq.EndReceive(a syncResult.Asyn cResult);


    // Display message information on the screen.

    //Console.WriteLi ne("Message: " + (string)m.Body) ;

    try

    {

    Console.WriteLi ne((string)m.Bo dy);

    }

    catch

    {

    }

    // Restart the asynchronous Receive operation.

    mq.BeginReceive ();


    return;

    }

    }

    class Class1

    {

    /// <summary>

    /// The main entry point for the application.

    /// </summary>

    static void Main(string[] args)

    {

    QueueWorker[] a = new QueueWorker[30] ;

    for(int i=0;i<30;i++)

    {

    a[i] = new QueueWorker(i) ;

    }

    while(true)

    {

    System.Threadin g.Thread.Sleep( 10000);

    }

    //

    // TODO: Add code to start application here

    //

    }

    }

    }


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: threading

    Avi,

    I didn't get a good look at your code but I think that the problem
    arises from the fact that the thread is not set up for COM interop properly
    (COM interop is used for the message queuing). I think that you should set
    up the thread by setting the ApartmentState property of the thread to
    ApartmentState. STA before any calls to the messaging components.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Avi Kadosh" <(N/A)> wrote in message
    news:%237x830ho DHA.424@TK2MSFT NGP10.phx.gbl.. .[color=blue]
    > hi all
    >
    > I am new to Csharp
    >
    > I tried the following code
    >
    > using System;
    >
    > using System.Threadin g;
    >
    > using System.Messagin g;
    >
    >
    > namespace ConsoleApplicat ion3
    >
    > {
    >
    > /// <summary>
    >
    > /// Summary description for Class1.
    >
    > /// </summary>
    >
    > ///
    >
    > class QueueWorker
    >
    > {
    >
    >
    > private MessageQueue MQueue;
    >
    > private int index;
    >
    > public QueueWorker(int ix)
    >
    > {
    >
    > index = ix;
    >
    > }
    >
    > public void CreateQueue()
    >
    > {
    >
    > if (!MessageQueue. Exists(".\\priv ate$\\" + index ))
    >
    > {
    >
    > MQueue = MessageQueue.Cr eate(".\\privat e$\\" + index , false);
    >
    > }
    >
    > else
    >
    > {
    >
    > MQueue = new MessageQueue(". \\private$\\" + index,true);
    >
    > }
    >
    > MQueue.Formatte r = new ActiveXMessageF ormatter();
    >
    > MQueue.ReceiveC ompleted += new
    > ReceiveComplete dEventHandler(M yReceiveComplet ed);
    >
    > MQueue.BeginRec eive() ;
    >
    > Console.WriteLi ne("Start Reciving on Queue " + index);
    >
    > Thread.CurrentT hread.Name = "My Queue Hadle Thread " + index;
    >
    >
    >
    > }
    >
    > private void MyReceiveComple ted(Object source,
    >
    > ReceiveComplete dEventArgs asyncResult)
    >
    > {
    >
    > // Connect to the queue.
    >
    > MessageQueue mq = (MessageQueue)s ource;
    >
    > // End the asynchronous Receive operation.
    >
    > Message m = mq.EndReceive(a syncResult.Asyn cResult);
    >
    >
    > // Display message information on the screen.
    >
    > //Console.WriteLi ne("Message: " + (string)m.Body) ;
    >
    > try
    >
    > {
    >
    > Console.WriteLi ne((string)m.Bo dy);
    >
    > }
    >
    > catch
    >
    > {
    >
    > }
    >
    > // Restart the asynchronous Receive operation.
    >
    > mq.BeginReceive ();
    >
    >
    > return;
    >
    > }
    >
    > }
    >
    > class Class1
    >
    > {
    >
    > /// <summary>
    >
    > /// The main entry point for the application.
    >
    > /// </summary>
    >
    > static void Main(string[] args)
    >
    > {
    >
    > QueueWorker[] a = new QueueWorker[30] ;
    >
    > for(int i=0;i<30;i++)
    >
    > {
    >
    > a[i] = new QueueWorker(i) ;
    >
    > a[i].CreateQueue;
    >
    > }
    >
    > while(true)
    >
    > {
    >
    > System.Threadin g.Thread.Sleep( 10000);
    >
    > }
    >
    > //
    >
    > // TODO: Add code to start application here
    >
    > //
    >
    > }
    >
    > }
    >
    > }
    >
    >
    >
    > it is working fine the problem is when I tried to change it to[/color]
    multithreaded[color=blue]
    > application (each queue worker is runing in it's own queue)
    >
    > it create the thread but stop reciving events ... any ideas?
    >
    >
    >
    > using System;
    >
    > using System.Threadin g;
    >
    > using System.Messagin g;
    >
    >
    > namespace ConsoleApplicat ion3
    >
    > {
    >
    > /// <summary>
    >
    > /// Summary description for Class1.
    >
    > /// </summary>
    >
    > ///
    >
    > class QueueWorker
    >
    > {
    >
    >
    > private MessageQueue MQueue;
    >
    > private int index;
    >
    > public QueueWorker(int ix)
    >
    > {
    >
    > index = ix;
    >
    > Thread myThread = new Thread(new ThreadStart(thi s.CreateQueue)) ;
    >
    > myThread.Start( );
    >
    > }
    >
    > public void CreateQueue()
    >
    > {
    >
    > if (!MessageQueue. Exists(".\\priv ate$\\" + index ))
    >
    > {
    >
    > MQueue = MessageQueue.Cr eate(".\\privat e$\\" + index , false);
    >
    > }
    >
    > else
    >
    > {
    >
    > MQueue = new MessageQueue(". \\private$\\" + index,true);
    >
    > }
    >
    > MQueue.Formatte r = new ActiveXMessageF ormatter();
    >
    > MQueue.ReceiveC ompleted += new
    > ReceiveComplete dEventHandler(M yReceiveComplet ed);
    >
    > MQueue.BeginRec eive() ;
    >
    > Console.WriteLi ne("Start Reciving on Queue " + index);
    >
    > Thread.CurrentT hread.Name = "My Queue Hadle Thread " + index;
    >
    >
    >
    > }
    >
    > private void MyReceiveComple ted(Object source,
    >
    > ReceiveComplete dEventArgs asyncResult)
    >
    > {
    >
    > // Connect to the queue.
    >
    > MessageQueue mq = (MessageQueue)s ource;
    >
    > // End the asynchronous Receive operation.
    >
    > Message m = mq.EndReceive(a syncResult.Asyn cResult);
    >
    >
    > // Display message information on the screen.
    >
    > //Console.WriteLi ne("Message: " + (string)m.Body) ;
    >
    > try
    >
    > {
    >
    > Console.WriteLi ne((string)m.Bo dy);
    >
    > }
    >
    > catch
    >
    > {
    >
    > }
    >
    > // Restart the asynchronous Receive operation.
    >
    > mq.BeginReceive ();
    >
    >
    > return;
    >
    > }
    >
    > }
    >
    > class Class1
    >
    > {
    >
    > /// <summary>
    >
    > /// The main entry point for the application.
    >
    > /// </summary>
    >
    > static void Main(string[] args)
    >
    > {
    >
    > QueueWorker[] a = new QueueWorker[30] ;
    >
    > for(int i=0;i<30;i++)
    >
    > {
    >
    > a[i] = new QueueWorker(i) ;
    >
    > }
    >
    > while(true)
    >
    > {
    >
    > System.Threadin g.Thread.Sleep( 10000);
    >
    > }
    >
    > //
    >
    > // TODO: Add code to start application here
    >
    > //
    >
    > }
    >
    > }
    >
    > }
    >
    >[/color]


    Comment

    • Avi Kadosh

      #3
      Re: threading

      Hi,

      Thanks for your replay.

      I tried to define it with STA for the same result...

      Also I don't use COM but the framework assamblies for queue ...

      Thanks,

      Avi

      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
      message news:%23xSsIQio DHA.360@TK2MSFT NGP12.phx.gbl.. .[color=blue]
      > Avi,
      >
      > I didn't get a good look at your code but I think that the problem
      > arises from the fact that the thread is not set up for COM interop[/color]
      properly[color=blue]
      > (COM interop is used for the message queuing). I think that you should[/color]
      set[color=blue]
      > up the thread by setting the ApartmentState property of the thread to
      > ApartmentState. STA before any calls to the messaging components.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "Avi Kadosh" <(N/A)> wrote in message
      > news:%237x830ho DHA.424@TK2MSFT NGP10.phx.gbl.. .[color=green]
      > > hi all
      > >
      > > I am new to Csharp
      > >
      > > I tried the following code
      > >
      > > using System;
      > >
      > > using System.Threadin g;
      > >
      > > using System.Messagin g;
      > >
      > >
      > > namespace ConsoleApplicat ion3
      > >
      > > {
      > >
      > > /// <summary>
      > >
      > > /// Summary description for Class1.
      > >
      > > /// </summary>
      > >
      > > ///
      > >
      > > class QueueWorker
      > >
      > > {
      > >
      > >
      > > private MessageQueue MQueue;
      > >
      > > private int index;
      > >
      > > public QueueWorker(int ix)
      > >
      > > {
      > >
      > > index = ix;
      > >
      > > }
      > >
      > > public void CreateQueue()
      > >
      > > {
      > >
      > > if (!MessageQueue. Exists(".\\priv ate$\\" + index ))
      > >
      > > {
      > >
      > > MQueue = MessageQueue.Cr eate(".\\privat e$\\" + index , false);
      > >
      > > }
      > >
      > > else
      > >
      > > {
      > >
      > > MQueue = new MessageQueue(". \\private$\\" + index,true);
      > >
      > > }
      > >
      > > MQueue.Formatte r = new ActiveXMessageF ormatter();
      > >
      > > MQueue.ReceiveC ompleted += new
      > > ReceiveComplete dEventHandler(M yReceiveComplet ed);
      > >
      > > MQueue.BeginRec eive() ;
      > >
      > > Console.WriteLi ne("Start Reciving on Queue " + index);
      > >
      > > Thread.CurrentT hread.Name = "My Queue Hadle Thread " + index;
      > >
      > >
      > >
      > > }
      > >
      > > private void MyReceiveComple ted(Object source,
      > >
      > > ReceiveComplete dEventArgs asyncResult)
      > >
      > > {
      > >
      > > // Connect to the queue.
      > >
      > > MessageQueue mq = (MessageQueue)s ource;
      > >
      > > // End the asynchronous Receive operation.
      > >
      > > Message m = mq.EndReceive(a syncResult.Asyn cResult);
      > >
      > >
      > > // Display message information on the screen.
      > >
      > > //Console.WriteLi ne("Message: " + (string)m.Body) ;
      > >
      > > try
      > >
      > > {
      > >
      > > Console.WriteLi ne((string)m.Bo dy);
      > >
      > > }
      > >
      > > catch
      > >
      > > {
      > >
      > > }
      > >
      > > // Restart the asynchronous Receive operation.
      > >
      > > mq.BeginReceive ();
      > >
      > >
      > > return;
      > >
      > > }
      > >
      > > }
      > >
      > > class Class1
      > >
      > > {
      > >
      > > /// <summary>
      > >
      > > /// The main entry point for the application.
      > >
      > > /// </summary>
      > >
      > > static void Main(string[] args)
      > >
      > > {
      > >
      > > QueueWorker[] a = new QueueWorker[30] ;
      > >
      > > for(int i=0;i<30;i++)
      > >
      > > {
      > >
      > > a[i] = new QueueWorker(i) ;
      > >
      > > a[i].CreateQueue;
      > >
      > > }
      > >
      > > while(true)
      > >
      > > {
      > >
      > > System.Threadin g.Thread.Sleep( 10000);
      > >
      > > }
      > >
      > > //
      > >
      > > // TODO: Add code to start application here
      > >
      > > //
      > >
      > > }
      > >
      > > }
      > >
      > > }
      > >
      > >
      > >
      > > it is working fine the problem is when I tried to change it to[/color]
      > multithreaded[color=green]
      > > application (each queue worker is runing in it's own queue)
      > >
      > > it create the thread but stop reciving events ... any ideas?
      > >
      > >
      > >
      > > using System;
      > >
      > > using System.Threadin g;
      > >
      > > using System.Messagin g;
      > >
      > >
      > > namespace ConsoleApplicat ion3
      > >
      > > {
      > >
      > > /// <summary>
      > >
      > > /// Summary description for Class1.
      > >
      > > /// </summary>
      > >
      > > ///
      > >
      > > class QueueWorker
      > >
      > > {
      > >
      > >
      > > private MessageQueue MQueue;
      > >
      > > private int index;
      > >
      > > public QueueWorker(int ix)
      > >
      > > {
      > >
      > > index = ix;
      > >
      > > Thread myThread = new Thread(new ThreadStart(thi s.CreateQueue)) ;
      > >
      > > myThread.Start( );
      > >
      > > }
      > >
      > > public void CreateQueue()
      > >
      > > {
      > >
      > > if (!MessageQueue. Exists(".\\priv ate$\\" + index ))
      > >
      > > {
      > >
      > > MQueue = MessageQueue.Cr eate(".\\privat e$\\" + index , false);
      > >
      > > }
      > >
      > > else
      > >
      > > {
      > >
      > > MQueue = new MessageQueue(". \\private$\\" + index,true);
      > >
      > > }
      > >
      > > MQueue.Formatte r = new ActiveXMessageF ormatter();
      > >
      > > MQueue.ReceiveC ompleted += new
      > > ReceiveComplete dEventHandler(M yReceiveComplet ed);
      > >
      > > MQueue.BeginRec eive() ;
      > >
      > > Console.WriteLi ne("Start Reciving on Queue " + index);
      > >
      > > Thread.CurrentT hread.Name = "My Queue Hadle Thread " + index;
      > >
      > >
      > >
      > > }
      > >
      > > private void MyReceiveComple ted(Object source,
      > >
      > > ReceiveComplete dEventArgs asyncResult)
      > >
      > > {
      > >
      > > // Connect to the queue.
      > >
      > > MessageQueue mq = (MessageQueue)s ource;
      > >
      > > // End the asynchronous Receive operation.
      > >
      > > Message m = mq.EndReceive(a syncResult.Asyn cResult);
      > >
      > >
      > > // Display message information on the screen.
      > >
      > > //Console.WriteLi ne("Message: " + (string)m.Body) ;
      > >
      > > try
      > >
      > > {
      > >
      > > Console.WriteLi ne((string)m.Bo dy);
      > >
      > > }
      > >
      > > catch
      > >
      > > {
      > >
      > > }
      > >
      > > // Restart the asynchronous Receive operation.
      > >
      > > mq.BeginReceive ();
      > >
      > >
      > > return;
      > >
      > > }
      > >
      > > }
      > >
      > > class Class1
      > >
      > > {
      > >
      > > /// <summary>
      > >
      > > /// The main entry point for the application.
      > >
      > > /// </summary>
      > >
      > > static void Main(string[] args)
      > >
      > > {
      > >
      > > QueueWorker[] a = new QueueWorker[30] ;
      > >
      > > for(int i=0;i<30;i++)
      > >
      > > {
      > >
      > > a[i] = new QueueWorker(i) ;
      > >
      > > }
      > >
      > > while(true)
      > >
      > > {
      > >
      > > System.Threadin g.Thread.Sleep( 10000);
      > >
      > > }
      > >
      > > //
      > >
      > > // TODO: Add code to start application here
      > >
      > > //
      > >
      > > }
      > >
      > > }
      > >
      > > }
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Avi Kadosh

        #4
        Re: threading

        I was able to narrow down the problem,

        When the thread is started the events is fired with no reason, then since
        there was no message in the queue and since I didn;t handle the exciption
        the thread was destoyed.

        any ideas, why the event was fired although there was nothing in the queue.

        "Avi Kadosh" <(N/A)> wrote in message
        news:%23JCscoio DHA.2808@TK2MSF TNGP10.phx.gbl. ..[color=blue]
        > Hi,
        >
        > Thanks for your replay.
        >
        > I tried to define it with STA for the same result...
        >
        > Also I don't use COM but the framework assamblies for queue ...
        >
        > Thanks,
        >
        > Avi
        >
        > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote[/color]
        in[color=blue]
        > message news:%23xSsIQio DHA.360@TK2MSFT NGP12.phx.gbl.. .[color=green]
        > > Avi,
        > >
        > > I didn't get a good look at your code but I think that the problem
        > > arises from the fact that the thread is not set up for COM interop[/color]
        > properly[color=green]
        > > (COM interop is used for the message queuing). I think that you should[/color]
        > set[color=green]
        > > up the thread by setting the ApartmentState property of the thread to
        > > ApartmentState. STA before any calls to the messaging components.
        > >
        > > Hope this helps.
        > >
        > >
        > > --
        > > - Nicholas Paldino [.NET/C# MVP]
        > > - mvp@spam.guard. caspershouse.co m
        > >
        > > "Avi Kadosh" <(N/A)> wrote in message
        > > news:%237x830ho DHA.424@TK2MSFT NGP10.phx.gbl.. .[color=darkred]
        > > > hi all
        > > >
        > > > I am new to Csharp
        > > >
        > > > I tried the following code
        > > >
        > > > using System;
        > > >
        > > > using System.Threadin g;
        > > >
        > > > using System.Messagin g;
        > > >
        > > >
        > > > namespace ConsoleApplicat ion3
        > > >
        > > > {
        > > >
        > > > /// <summary>
        > > >
        > > > /// Summary description for Class1.
        > > >
        > > > /// </summary>
        > > >
        > > > ///
        > > >
        > > > class QueueWorker
        > > >
        > > > {
        > > >
        > > >
        > > > private MessageQueue MQueue;
        > > >
        > > > private int index;
        > > >
        > > > public QueueWorker(int ix)
        > > >
        > > > {
        > > >
        > > > index = ix;
        > > >
        > > > }
        > > >
        > > > public void CreateQueue()
        > > >
        > > > {
        > > >
        > > > if (!MessageQueue. Exists(".\\priv ate$\\" + index ))
        > > >
        > > > {
        > > >
        > > > MQueue = MessageQueue.Cr eate(".\\privat e$\\" + index , false);
        > > >
        > > > }
        > > >
        > > > else
        > > >
        > > > {
        > > >
        > > > MQueue = new MessageQueue(". \\private$\\" + index,true);
        > > >
        > > > }
        > > >
        > > > MQueue.Formatte r = new ActiveXMessageF ormatter();
        > > >
        > > > MQueue.ReceiveC ompleted += new
        > > > ReceiveComplete dEventHandler(M yReceiveComplet ed);
        > > >
        > > > MQueue.BeginRec eive() ;
        > > >
        > > > Console.WriteLi ne("Start Reciving on Queue " + index);
        > > >
        > > > Thread.CurrentT hread.Name = "My Queue Hadle Thread " + index;
        > > >
        > > >
        > > >
        > > > }
        > > >
        > > > private void MyReceiveComple ted(Object source,
        > > >
        > > > ReceiveComplete dEventArgs asyncResult)
        > > >
        > > > {
        > > >
        > > > // Connect to the queue.
        > > >
        > > > MessageQueue mq = (MessageQueue)s ource;
        > > >
        > > > // End the asynchronous Receive operation.
        > > >
        > > > Message m = mq.EndReceive(a syncResult.Asyn cResult);
        > > >
        > > >
        > > > // Display message information on the screen.
        > > >
        > > > //Console.WriteLi ne("Message: " + (string)m.Body) ;
        > > >
        > > > try
        > > >
        > > > {
        > > >
        > > > Console.WriteLi ne((string)m.Bo dy);
        > > >
        > > > }
        > > >
        > > > catch
        > > >
        > > > {
        > > >
        > > > }
        > > >
        > > > // Restart the asynchronous Receive operation.
        > > >
        > > > mq.BeginReceive ();
        > > >
        > > >
        > > > return;
        > > >
        > > > }
        > > >
        > > > }
        > > >
        > > > class Class1
        > > >
        > > > {
        > > >
        > > > /// <summary>
        > > >
        > > > /// The main entry point for the application.
        > > >
        > > > /// </summary>
        > > >
        > > > static void Main(string[] args)
        > > >
        > > > {
        > > >
        > > > QueueWorker[] a = new QueueWorker[30] ;
        > > >
        > > > for(int i=0;i<30;i++)
        > > >
        > > > {
        > > >
        > > > a[i] = new QueueWorker(i) ;
        > > >
        > > > a[i].CreateQueue;
        > > >
        > > > }
        > > >
        > > > while(true)
        > > >
        > > > {
        > > >
        > > > System.Threadin g.Thread.Sleep( 10000);
        > > >
        > > > }
        > > >
        > > > //
        > > >
        > > > // TODO: Add code to start application here
        > > >
        > > > //
        > > >
        > > > }
        > > >
        > > > }
        > > >
        > > > }
        > > >
        > > >
        > > >
        > > > it is working fine the problem is when I tried to change it to[/color]
        > > multithreaded[color=darkred]
        > > > application (each queue worker is runing in it's own queue)
        > > >
        > > > it create the thread but stop reciving events ... any ideas?
        > > >
        > > >
        > > >
        > > > using System;
        > > >
        > > > using System.Threadin g;
        > > >
        > > > using System.Messagin g;
        > > >
        > > >
        > > > namespace ConsoleApplicat ion3
        > > >
        > > > {
        > > >
        > > > /// <summary>
        > > >
        > > > /// Summary description for Class1.
        > > >
        > > > /// </summary>
        > > >
        > > > ///
        > > >
        > > > class QueueWorker
        > > >
        > > > {
        > > >
        > > >
        > > > private MessageQueue MQueue;
        > > >
        > > > private int index;
        > > >
        > > > public QueueWorker(int ix)
        > > >
        > > > {
        > > >
        > > > index = ix;
        > > >
        > > > Thread myThread = new Thread(new ThreadStart(thi s.CreateQueue)) ;
        > > >
        > > > myThread.Start( );
        > > >
        > > > }
        > > >
        > > > public void CreateQueue()
        > > >
        > > > {
        > > >
        > > > if (!MessageQueue. Exists(".\\priv ate$\\" + index ))
        > > >
        > > > {
        > > >
        > > > MQueue = MessageQueue.Cr eate(".\\privat e$\\" + index , false);
        > > >
        > > > }
        > > >
        > > > else
        > > >
        > > > {
        > > >
        > > > MQueue = new MessageQueue(". \\private$\\" + index,true);
        > > >
        > > > }
        > > >
        > > > MQueue.Formatte r = new ActiveXMessageF ormatter();
        > > >
        > > > MQueue.ReceiveC ompleted += new
        > > > ReceiveComplete dEventHandler(M yReceiveComplet ed);
        > > >
        > > > MQueue.BeginRec eive() ;
        > > >
        > > > Console.WriteLi ne("Start Reciving on Queue " + index);
        > > >
        > > > Thread.CurrentT hread.Name = "My Queue Hadle Thread " + index;
        > > >
        > > >
        > > >
        > > > }
        > > >
        > > > private void MyReceiveComple ted(Object source,
        > > >
        > > > ReceiveComplete dEventArgs asyncResult)
        > > >
        > > > {
        > > >
        > > > // Connect to the queue.
        > > >
        > > > MessageQueue mq = (MessageQueue)s ource;
        > > >
        > > > // End the asynchronous Receive operation.
        > > >
        > > > Message m = mq.EndReceive(a syncResult.Asyn cResult);
        > > >
        > > >
        > > > // Display message information on the screen.
        > > >
        > > > //Console.WriteLi ne("Message: " + (string)m.Body) ;
        > > >
        > > > try
        > > >
        > > > {
        > > >
        > > > Console.WriteLi ne((string)m.Bo dy);
        > > >
        > > > }
        > > >
        > > > catch
        > > >
        > > > {
        > > >
        > > > }
        > > >
        > > > // Restart the asynchronous Receive operation.
        > > >
        > > > mq.BeginReceive ();
        > > >
        > > >
        > > > return;
        > > >
        > > > }
        > > >
        > > > }
        > > >
        > > > class Class1
        > > >
        > > > {
        > > >
        > > > /// <summary>
        > > >
        > > > /// The main entry point for the application.
        > > >
        > > > /// </summary>
        > > >
        > > > static void Main(string[] args)
        > > >
        > > > {
        > > >
        > > > QueueWorker[] a = new QueueWorker[30] ;
        > > >
        > > > for(int i=0;i<30;i++)
        > > >
        > > > {
        > > >
        > > > a[i] = new QueueWorker(i) ;
        > > >
        > > > }
        > > >
        > > > while(true)
        > > >
        > > > {
        > > >
        > > > System.Threadin g.Thread.Sleep( 10000);
        > > >
        > > > }
        > > >
        > > > //
        > > >
        > > > // TODO: Add code to start application here
        > > >
        > > > //
        > > >
        > > > }
        > > >
        > > > }
        > > >
        > > > }
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...