473,379 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to interrupt a running program

I'm writing a program to handle multiple tasks in a single batch, which may
take 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!
May 10 '06 #1
2 5426
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.

May 10 '06 #2
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 = False
Me.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?

May 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: bbxrider | last post by:
for win2k adv server/iis5.0 trying to run an external program from my asp routine that has multiple parameters, see following set shell = server.createobject("wscript.shell") shell.Run...
1
by: Reny | last post by:
Can any one tell me how do i write an interrpt driven program with .net?
0
by: joeted | last post by:
Hi, I am using system.diagnostic.process with the intention of running a program to communicate with a unix box: The program is "PuTTY", running from a batch script. I know it works because...
3
by: Reny J Joseph Thuthikattu | last post by:
Hi, I want to write a interrupt driven program with .NET .Can any one help? Reny
1
by: thomas.dahr | last post by:
Hi, How do I pick up a running program and bring it up front when I click it's shortcut, instead of starting a new copy of it? I know how to block by using CreateMutex, but how to activate the...
1
by: utpal | last post by:
Hi, My CSharp program, when I run from the local drive it can create/modify registry. However running the program from a network drive, gives RegistryPremission error. I don't belive that just by...
0
by: SapAddonDeveloper | last post by:
Hello, I am writing an add-on using vbnet/c# that runs inside a Sap B1 application. I need to be able to change the input language (little blue white icon on the system tray) on certain...
2
by: Paul Rubin | last post by:
I have a long-running program that has lots of net connections open on separate threads. I'm twiddling my thumbs waiting for it to finish (each run takes maybe an hour) and although I'm logging...
3
by: Ankit Khare | last post by:
"The heap grows and the stack decreases, both approach towards each other, if they crosses each other, program crashes" I have read this at a number of places but am confused in it. Each running...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.