Quantcast
Channel: VBForums - WPF, WCF, WF
Viewing all articles
Browse latest Browse all 256

[RESOLVED] WPF DispatcherTimer Threading issue

$
0
0
Ok - I've got this code

Code:

private void SendToReader(object sender, EventArgs ea) //(object objectState)
{
    //long tc = System.Threading.Interlocked.Increment(ref TimerClick);
    lock (mainTimer)
    {
        //mainTimer.Change(System.Threading.Timeout.Infinite, 250);
        mainTimer.IsEnabled = false;
    }
.
.
.
bool doContactReader = true;
while (doContactReader)
{
    if (cl2.asyncPostText("sessionid", ref rdFSOb, prefixes, cqMS, ref returnMessage))
    {
        doContactReader = false;
        SessionId = Convert.ToInt64(rdFSOb.FNTagsCollection[0]);
        this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (System.Threading.ThreadStart)delegate()
        {
            txtSearch.Text = "";
            txtSearch.IsEnabled = true;
            txtSearch.Focus();
        });
    }
    else
    {
        this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (System.Threading.ThreadStart)delegate()
        {
            if (MessageBox.Show("Reader is not responding - try again?", "Try Again or Cancel", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.Cancel)
            {
                doContactReader = false;
                txtSearch.Text = "";
            }
        });
    }
}

Running in a DispatcherTime

Code:

            mainTimer = new DispatcherTimer(DispatcherPriority.Normal);
            mainTimer.Interval = new TimeSpan(250);
            mainTimer.Tick += new EventHandler(SendToReader);
            mainTimer.IsEnabled = true;

And if you look at the image I've attached - if the reader responds it nicely clears the .Text and Enables it and sets the Focus.

So Break #1 hits

If the reader does not respond - as I am showing in the image that is attached - the BREAK is actually at the circled spot. That's good.

But it never gets to Break #2 - never pops up the message box.

What am I doing wrong?
Attached Images
 

Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>