Question

I want to show non-modal Information Window and wait for touch of smart card in other thread. I need to block my main UI thread to prevent user actions unless the smart card will be touched with card reader. I do it in main thread so:

InformationWindow infoWindow = new InformationWindow();
infoWindow.tblockInfo.Text = someInfoAboutRequieredAction;
infoWindow.Show();

Semaphore.WaitOne();

infoWindow.Close();

It works fine and is drawn normally in some cases, but my information WPF window is often not fully drawn. There is only Title part and no one control inside window (and background color) is visible as it's hanging

please help, i haven't understood for a week what to do

P.S. I have been tried InvalidateVisual(), UpdateLayout() and Thread.Sleep before Semaphore.WaitOne() but it hasn't helped

Was it helpful?

Solution

Blocking the Main UI thread is very different to blocking the UI. You would do better to disable the UI (e.g. MainWindow.IsEnabled = false) and leave the UI thread to draw the window.

This would also allow you to add a cancel button to your InformationWindow which can be used in case somebody kicks off this process and doesn't have a smart card to hand.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top