Status Message during function call (WPF, Multithreadin) - wpf

I have one "CleanUp" button on my WPF UI.By clicking on this button, I"ll call some C++ wrapper function to do some calculation.The calculation will take some time.
What I want exactly:
1. During calculation, I want to show some message like "Clean-Up is going on" besides one node of TreeView (TreeView is present on same UI.
Any help would be appreciated........

You can try by using a BackgroundWorker.
Just set a new background worker and set it's dowork event to your "wrapper function to do some calculation" ;-)
After that you can trigger the reportprogress event to set a new state or message while it's executing.

Related

Best way to introduce repeated action to a Button descendant

I'd like derive a class from Button to add an initial delay and interval which shall be used as long as the button is touched for repeated action.
At first thought this seems to be simple enough but the method com.codename1.ui.Button.setState(int) cannot be overridden because it has package access only. Is that for a good reason?
I noticed, that Button calls actionPerformed on pointerReleased. My Button descendant should call actionPerformed repeatedly but not wen the parent container of the Button is beeing scrolled. This would hopefully just correspond with the Button state STATE_PRESSED, right?
If I understand correctly what you mean then I'd just start a timer on the pressed method and then repeatedly call super.pressed & super.released whenever the timer elapses.

Trying to update the UI WPF

Inside my WPF application I have this code in my Demo_click event:
cmdDoMyThing is a ToggleButton
cmdDoMyThing.IsChecked = True
cmdDoMyThing.UpdateLayout()
Delay()
showAnotherDialog()
cmdDoMyThing.IsChecked = False
This is the Delay()
Sub Delay()
Thread.Sleep(2000)
End Sub
And my problem is that I want to update the UI inside the Demo_Click event, before this method finish. So the cmdDoMyThing is checked and display the state checked in the UI, then wait for 2 seconds, call the showAnotherDialog and when the user close the showAnotherDialog then cmdDoMyThing is unchecked, update the UI and continue the process inside the Demo_click event.
I am like crazy trying to make it work and I cannot find the way to do it.
Any suggestion? thank you in advance.
If i understand you correctly, i think you are looking for a modal window/dialog. Try this method when opening your dialog instead of show

In VB6 is there something similar to DialogResult from a dialog?

I have a VB6 form with buttons with the text 'Continue' and 'Cancel'. I want to check which one was clicked. In C# every form has a dialog result and I could set it before exiting the form depending on which button was clicked. I don't see this in VB6.
Is there a dialog result? If not what is the best practice for checking the dialog result?
To simulate the .net WinForms behaviour, you will need a helper function in your form's code:
Public Function ShowDialog() As VbMsgBoxResult
Me.Show vbModal
ShowDialog = Iif(Cancelled, vbCancel, vbOk)
Unload Me
End Function
The form level Cancelled variable can be set by the button event functions before calling .Hide() or .Close(), or you could have a variable containing the result code directly.
In VB6 a dialog generally returns an integer value, which may correspond to vbYes, vbNo, vbCancel, etc.
See this article for details: http://www.vb6.us/tutorials/understanding-msgbox-command-visual-basic
http://www.code-vb.com/fragments/Dialogs.htm#Msgbox OK-Cancel
You'll have to specify it on your form if you've created the form yourself.
The last answer in this post has a hint that may help: http://www.xtremevbtalk.com/archive/index.php/t-306663.html

Can SetWindowHookEx(WH_CALLWNDPROC ) hang entire system?

I am stuck with this. I can't even see the debug output using OutputDebugString and debugview - the system just hangs.
One question is: if i call SendMessage() inside hook function, did this message comes to me back into my hook function or system just calls another handlers but not my?
Question two: I am using hook procedure to catch messages sent by the system when a user clicks the tray icons or moves the mouse over the icons.
Is this correct way using SetWindowHookEx(WH_CALLWNDPROC, myfunc, hDll, 0) or should I use the thread parameter and set it to the thread which recieves msgs as configured by Shell_NotifyIcon()?
You implemented the hook in a library!?
Regarding question 1: I would not call SendMessage inside the hook because this SendMessage again will let your hook being called. This might lead to a recursion.
Regarding question 2: You are using hooks to get notified when a tray icon was clicked? Do you want to now when ANY tray icon was clicked or when YOUR tray icon was clicked? For notifications about your tray icon you should use Shell_NotifyIcon and take a look at NOTIFYICONDATA::uCallbackMessage.

Silverlight click event registered a second time before first event completed

I have a button which launches a "modal dialog" - it just creates a transparent grid covering everything, with the "dialog" created on top of that.
However I have a strange issue - if I double/triple click the button really fast (or add some delay in the event code), the button click event is executed multiple times, creating multiple overlapping modal dialogs. If the first action in my event is to disable the button (IsEnabled=false) it seems to prevent this.
My guess is that Silverlight is being multithreaded with input - it is not only recording the second click in another thread (while the button's click event is running), but it is jumping the gun by evaluating which control should be the target before the previous event has finished executing. Even though that event alters what control is at those mouse coordinates, it doesn't matter.
Does anyone know anything about this behavoir, or a way around it? If I have something like a save window, where the user clicks a save button, a blocking grid ("Saving...") is placed up while it saves, and then the whole "window" is closed, I'd like to avoid the user being able to queue up multiple save event clicks (this could lead to unpredictable program behavoir).
If you've ever worked with WinForms or WPF, this is expected behavior. Your button is broadcasting its Click event until your modal dialog covers it up. Unfortunately, there is some amount of time between your first click and when the modal dialog covers the button which allows multiple clicks to the original button.
You have two solution choices:
Disable the button after the first click and then re-enable after the modal dialog returns. You've already mentioned that this works.
Write code in the Event Handler of the button to determine if a modal dialog is already being displayed. This way, you're putting the responsibility in one location rather than splitting it up (disabling and re-enabling the button). This would be my preferred solution.
I think what you're seeing is the behaviour of Silverlight's routed events.
You can set the Handled property of the event arguments to true to prevent the event from bubbling.

Resources