Search code examples
c#asp.netwcf

C# How to implement flag messaging system between two methods in a business logic class of a WCF app?


I have two methods in a C# business logic class. I need a flag mechanism so that one method can update the flag and the other method will react when the flag is updated. Below I will paste my situation, which is very simple:

// BusinessLogic.cs
bool photoResizingFinished = false;

public int SavePhoto() {

while (!photoResizingFinished)  {
    System.Threading.Thread.Sleep(100);
        Trace.TraceInformation("PhotoResizingWorkerRole has not finnished yet.");
     } }

public bool UpdateStatus(bool statusUpdate) {
   photoResizingFinished = statusUpdate;
   return true; 
}

The two methods above live in the same class BusinessLogic.cs.

The only thing I need is to be able to have SavePhoto() react when the bool photoResizingFinished is updated by UpdateStatus(bool statusUpdate)


Solution

  • Maybe I have found a solution to my problem using a Multithreaded Singleton

    http://msdn.microsoft.com/en-us/library/ff650316.aspx

    Here are some attempts of implementation:

    http://forums.asp.net/t/1783765.aspx/2/10?How+to+have+two+methods+of+the+same+class+flag+to+eachother+

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/abd53523-658b-442a-bac0-1c74c1d90a90

    I don't understand the mecanics of this myself totally, but I hope it's ok.