Maybe a threading issue?

Hi,

I am currently using a timer to trigger an event every x seconds. The trigger is supposed to step through two functions. The first one creates a file in the in a directory, the second then Posts it to an online database using an async method. Below is the code:

public void myTimerControl(bool cbChecked){
        if (cbChecked) {

            if (_myTimer == null) {
                _myTimer = new System.Timers.Timer(1000);
                _myTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
                }
            _myTimer.Enabled = true;
            GC.KeepAlive(_myTimer);
        } 
        else 
        {      _myTimer.Stop();
            _myTimer.Enabled = false;
        }
    }

    private void OnTimedEvent(object source, ElapsedEventArgs e)
    {
        try{    
            CreatePostingFile ();
            ProcessNextFile();
        }
        catch(System.OperationCanceledException){
            Console.Write ("***Error***");
        }
    } 

So every second the OnTimedEvent does fire, but it will only hit the first function (CreatePostingFile). It never hits the second one. If I switch the function order around it still does the same thing. Does anybody have any knowledge on why this happens?

Thank You.

Sign In or Register to comment.