CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #3
    Join Date
    Feb 2012
    Location
    Strasbourg, France
    Posts
    116

    Re: Delegate, Invoke, Threads and anormal bug

    Oppps DynamicInvoke was a test to see if it would work better so here's the original version :
    Code:
            private static void OnStatusChanged(EventPourUpdateLog e)
            {
                StatusChangedEventHandler statusHandler = StatusChanged;
                if (statusHandler != null)
                {
                    // Invoque le délégué
                    statusHandler(null, e);
                     //statusHandler.DynamicInvoke(null, e);
                }
            }
    textBoxLog is err.... a textBox


    No exception thrown. Breakpoint and stepinto just go in freeze when reaching UpdateLog


    Ok let's try your method, here's the piece of code failing let's see how commenting changes it.

    Code:
    1.                Console.WriteLine("1");
    2.                UpdateLog("[INFO] Fermeture listener" + Environment.NewLine);
    3.                Console.WriteLine("2");
    4.                myListener.Stop();
    5.                Console.WriteLine("3");
    6.                UpdateLog("[INFO] Listener fermé" + Environment.NewLine);
    7.                Console.WriteLine("4");
    8.                FermetureListener.Set();
    9.                Console.WriteLine("5");
    I'll follow your commeting scenario : Serveur.UpdateLog(string) --> Serveur.OnStatusChanged(...) --> /* via event */ --> FauxServeur.StatusChanged(...) --> FauxServeur.UpdateLog(string) --> textBoxLog.AppendText(string)

    Of course I uncomment the previous each time.


    1st case : nothing commented

    Last line executed was line 5


    2nd case : commenting line 6

    Complete execution. Line 9 was executed


    3rd case : commenting Serveur.OnStatusChanged(...) inside the Serveur.UpdateLog function

    Complete execution. Line 9 was executed


    4th case : commenting statusHandler(null, e); inside Serveur.OnStatusChanged

    Complete execution. Line 9 was executed


    5th case : commenting this.Invoke(new DeleguePourUpdateLog(this.UpdateLog), new object[] { e.message }); inside FauxServeur.StatusChanged()

    Complete execution. Line 9 was executed


    6th case : commenting textBoxLog.AppendText(s); inside FauxServeur.UpdateLog()

    Line 3 never reached going further inside to find where it stopped

    This is Serveur.UpdateLog()
    Code:
            public static void UpdateLog(String Message)
            {
                Console.WriteLine("21");
                e = new EventPourUpdateLog(Message);
                Console.WriteLine("22");
                OnStatusChanged(e);
                Console.WriteLine("23");
            }
    Console.WriteLine("23"); is never reached. Going further inside.



    This is Serveur.OnStatusChanged
    Code:
            private static void OnStatusChanged(EventPourUpdateLog e)
            {
                Console.WriteLine("30");
                StatusChangedEventHandler statusHandler = StatusChanged;
                Console.WriteLine("31");
                if (statusHandler != null)
                {
                    Console.WriteLine("32");
                    // Invoque le délégué
                    statusHandler(null, e);
                    Console.WriteLine("33");
                     //statusHandler.DynamicInvoke(null, e);
                }
            }
    Console.WriteLine("33"); is never reached. Going further inside.

    This is FauxServeur.StatusChanged()
    Code:
            public void StatusChanged(object sender, EventPourUpdateLog e)
            {
                Console.WriteLine("40");
                this.Invoke(new DeleguePourUpdateLog(this.UpdateLog), new object[] { e.message });
                Console.WriteLine("41");
            }
    Console.WriteLine("41"); is never reached. Going further inside.

    Here is in this case the code for FauxServeur.UpdateLog()
    Code:
            private void UpdateLog(String s)
            {
                Console.WriteLine("50");
                //textBoxLog.AppendText(s);
                Console.WriteLine("51");
            }
    Console.WriteLine("50"); is never reached canno't go further :/


    Any idea ? for the moment the programs runs by being executed in case n°2

    Thanks !
    Last edited by Erendar; April 3rd, 2012 at 02:19 AM. Reason: typo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured