|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to interrupt a running programtake few minutes to complete all tasks. To reduce the impact to user, no windows form will be displayed, instead I have create a NotifiyIcon for the program, it can show the current status whenever user put the mouse over the tray icon. As it takes time to complete all tasks, user may want to terminate the job for some reason. I have added the ContextMenu for the NotifyIcon, and user can choose the option to terminate the job. Everything seems OKay, and I can call the menu when the program started before I trigger the job (the job will starte 1 minute after the proram executed). However, if the job is started, the NotifyIcon can show the status when user put the mouse over the icon, but there has no response when i clicked on the icon, the menu does not show up. If i remove the application.exit() after I complete all task, and let the icon remain here. I found that the menu will pop up after i finish the task. I have try to add some code in the loop after each task, to check if user attempt to stop it. But it seems that all event on the notifyicon will not execute unless the function is completed. So, i cannot set the viriable to stop the job after one task. When I'm using other language before, I can add a function like yield() inside my program to release the CPU, so that i can handle other events. I'd like to know if VB.Net has similiar function to allow the CPU to handle other event of my program (e.g. mouse click on the notifyicon) while it's inside a function. Thanks in advance! In VB that function is Application.DoEvents(). But you might also want
to spawn a separate thread to handle your time consuming task so the UI (in this case the tray icon) will remain responsive. Thanks a lot!
I have no experience in program with thread. Just read the help from MSDN ("Creating Threads and Passing Data at Start Time "), and I have modified my program by replacing the orignal script for running all task as, Dim myThread As New Thread(AddressOf Me.RunAllTask) myThread.Start() Then put the original code in the function RunAllTask. Private Sub RunAllTask() : <original codes to execute the tasks> : NotifyIcon.Visible = FalseMe.Close() Application.Exit() End Sub As i will close the application after all task completed, i put exit codes at the end. I have tested the program, it works fine. And I can now put the code to terminate the loop in the menu. Is it the way you want me to changed? May I know if there has any error handling required in this changes?
Mailmerge Automation Problems
Date Errors in .NET 2.0 Dynamically adding a stylesheet VB Form: Controlbox = False byte array size for read or write of filestream Basic Database Questions Optional X as Boolean = ??? to detect missing argument? How do I embed a text file in my exe? mutiple tables in dataset and the dataadapter fill statement problem with code for dataset with mutilple tables |
|||||||||||||||||||||||