none
Do Post call a function or pass a message to an infinite loop function RRS feed

  • Question

  • do 

    _logPort.Post("task1 " + i);

    pass a message to a function or call a function

    if pass a message to a function, how the message updated in an infinite loop which already run

    private static readonly Port<string> _logPort = new Port<string>();
            public static void task1(String msg)
            {
                while (true)
                {
                    Console.WriteLine(msg);
                    Thread.Sleep(1000);
                }
            }
            static void Main(string[] args)
            {
                using (DispatcherQueue dq = new DispatcherQueue())
                {
                    Arbiter.Activate(dq, Arbiter.Receive(true, _logPort, task1));
    
                    for (int i = 0; i < 3; ++i)
                    {
    
                        _logPort.Post("task1 " + i);
                        Thread.Sleep(1000);
                        _logPort.Post("task2 " + i);
                    }
                    Console.ReadLine();
                }
    


    ---v-----!

    Monday, October 28, 2013 5:32 AM

Answers

  • Um, I'm still not 100% certain I understand your question, but one thing I might suggest is to NOT use Console.WriteLine.

    From my understanding of older posts on this forum (really, really older, like 2007 :-)), as well as within the help documentation, the invocation of Console.WriteLine knows nothing about potential interleave coordination setup by your 

    "Arbiter.Activate(dq, Arbiter.Receive(true, _logPort, task1);"

    statement.  This is also true for your

    "Thread.Sleep(1000);"

    statement.

    Thus, what you see in the console window is not always chronologically accurate.  Also, the DispatcherQueue's behavior is NOT identical to the AutoEvent and WaitOne mechanisms.

    You might try to place your test within a DSS service and then make use of the ConsolePort member for a more accurate console window presentation.


    Dennis M. Knippel

    Wednesday, October 30, 2013 5:29 PM
    Moderator

All replies

  • Hi, I am not sure I understand what you are trying to do or what your problem is. Could you please be more specific?
    Monday, October 28, 2013 9:47 AM
    Moderator
  • i add Console.WriteLine("start task1");

    it show that .Post is calling a function, it seems not like WaitOne to signal the thread

    Initially i think task1 is made as a thread and passed to dispatcherqueue 

    public static void task1(String msg) {

    Console.WriteLine("start task1"); while (true) { Console.WriteLine(msg); Thread.Sleep(1000); } }



    ---v-----!


    Tuesday, October 29, 2013 10:05 AM
  • Sorry, still not understanding. What is the output you see from this and how does it differ from what you'd expect?
    Tuesday, October 29, 2013 4:52 PM
    Moderator
  • Wow, I'd have to agree with Greg & Ashley.  It is quite difficult to understand your question.  Please try again to clearly state what you are asking.

    Dennis M. Knippel

    Tuesday, October 29, 2013 9:23 PM
    Moderator
  • the result is that it show many times Console.WriteLine("start task1");

    it seems calling function task1 directly, not like a thread

    Originally i think that design is like AutoEvent and WaitOne to signal the thread which is an

    infinite loop


    ---v-----!

    Wednesday, October 30, 2013 6:47 AM
  • Um, I'm still not 100% certain I understand your question, but one thing I might suggest is to NOT use Console.WriteLine.

    From my understanding of older posts on this forum (really, really older, like 2007 :-)), as well as within the help documentation, the invocation of Console.WriteLine knows nothing about potential interleave coordination setup by your 

    "Arbiter.Activate(dq, Arbiter.Receive(true, _logPort, task1);"

    statement.  This is also true for your

    "Thread.Sleep(1000);"

    statement.

    Thus, what you see in the console window is not always chronologically accurate.  Also, the DispatcherQueue's behavior is NOT identical to the AutoEvent and WaitOne mechanisms.

    You might try to place your test within a DSS service and then make use of the ConsolePort member for a more accurate console window presentation.


    Dennis M. Knippel

    Wednesday, October 30, 2013 5:29 PM
    Moderator