473,657 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to interupt code execution in a method

I need to make a program that will import data from a
text file into a database.
I have already designed the user interface, and I am
coding a class to open the file and handle the data. Now
an object of the class will be initialised and I will
call the data procedure in it though a method, and pass
it ref parameter for update of a counter in the user
interface, when the user press a start button. All that
seems fine.

However, if the user needs to stop the operation, I need
to somehow be able to break the import. I guess that I
could have a stop button, which could call another method
in the object, that would set a private cancel variable
for the object to the value true. The running import
procedure could then check on the cancel variable.
However, would that ever work, since the first method
that is doing the import, is not complete yet?

Is this a situation where another thread needs to be
used? I have not been working with threads before, so if
this is the case, perhaps someone can explain a bit, and
direct me to some articles in the help system that will
clarify this.
With kind regards,

Frank
Nov 20 '05 #1
7 1476
Hi Crirus,

There is no attachment the posting. I don't think you can
attach to newsgroup postings.
Perhaps you can include a link to a webpage instead.
Regards,

Frank

-----Original Message-----
Hi!
Check out this attach...!
Regards,

Crirus

Nov 20 '05 #2
Yes, there is I use outlook express and I can see my zip attached ....
"Frank" <an*******@disc ussions.microso ft.com> wrote in message
news:0a******** *************** *****@phx.gbl.. .
Hi Crirus,

There is no attachment the posting. I don't think you can
attach to newsgroup postings.
Perhaps you can include a link to a webpage instead.
Regards,

Frank

-----Original Message-----
Hi!
Check out this attach...!
Regards,

Crirus

Nov 20 '05 #3
Hi Crisus,

Ok, I won't argue with you there :-).
However, I access the newsgroups through the MSDN website
(http://msdn.microsoft.com/newsgroups/) and I think they
strip all attachments for security reasons. Also, I
access the newsgroups from more than one computer, so
prefer to read them this way).

Perhaps you could be so kind as to direct me to a
webpage, or perhaps there is no such?
With kind regards,

Frank

-----Original Message-----
Yes, there is I use outlook express and I can see my zip attached ....

"Frank" <an*******@disc ussions.microso ft.com> wrote in messagenews:0a******* *************** ******@phx.gbl. ..
Hi Crirus,

There is no attachment the posting. I don't think you can attach to newsgroup postings.
Perhaps you can include a link to a webpage instead.
Regards,

Frank

>-----Original Message-----
>Hi!
>Check out this attach...!
>
>
>Regards,
>
>Crirus
>
>
>

.

Nov 20 '05 #4
Hi Frank,

I use OE too, so the attachment's fine.
Here's Crirus's code.

Regards,
Fergus

ps. This uses a TextBox for demonstation which is fine here, but is not the
recommended way to interact with UI Controls. For that you need to call
oControl.BeginI nvoke.

=============== =============== =============
<ThreadWorker.v b>
Imports System.Threadin g

Public Class ThreadWorker

' members...
Public TextBox As TextBox
Private _thread As Thread

' Start - this method is the entry-point for the thread...
Private Sub Start()

' just set some text on the textbox...
TextBox.Text = "Hello, world from thread " & _
_thread.Name & " #" & _
Thread.CurrentT hread.GetHashCo de() & "!"
End Sub

' SpinUp - this method is called by the main application thread...
Public Sub SpinUp()

' create a thread start object that refers to our worker...
Dim threadStart As ThreadStart
threadStart = New ThreadStart(Add ressOf Me.Start)

' now, create the thread object and start it...
_thread = New Thread(threadSt art)
_thread.Name = "Worker"
_thread.Start()

End Sub

End Class
</ThreadWorker.vb >

<Form1.vb>
Imports System.Threadin g

Add a TextBox - txtResult
Add a Button - btnStartThread

Private Sub Form1_Load(ByVa l sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load

Thread.CurrentT hread.Name = "Main"
Me.Text &= " - Thread Main #" & Thread.CurrentT hread.GetHashCo de
End Sub

Private Sub btnStartThread_ Click(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles btnStartThread. Click

' create a new worker...
Dim worker As New ThreadWorker()
worker.TextBox = txtResult

' spin up the thread...
worker.SpinUp()
End Sub
</Form1.vb>
Nov 20 '05 #5
Thanks,

Frank
-----Original Message-----
Hi Frank,

I use OE too, so the attachment's fine.
Here's Crirus's code.

Regards,
Fergus

ps. This uses a TextBox for demonstation which is fine here, but is not therecommended way to interact with UI Controls. For that you need to calloControl.Begin Invoke.

============== =============== ==============
<ThreadWorker. vb>
Imports System.Threadin g

Public Class ThreadWorker

' members...
Public TextBox As TextBox
Private _thread As Thread

' Start - this method is the entry-point for the thread... Private Sub Start()

' just set some text on the textbox...
TextBox.Text = "Hello, world from thread " & _
_thread.Name & " #" & _
Thread.CurrentT hread.GetHashCo de() & "!"
End Sub

' SpinUp - this method is called by the main application thread... Public Sub SpinUp()

' create a thread start object that refers to our worker... Dim threadStart As ThreadStart
threadStart = New ThreadStart(Add ressOf Me.Start)

' now, create the thread object and start it...
_thread = New Thread(threadSt art)
_thread.Name = "Worker"
_thread.Start()

End Sub

End Class
</ThreadWorker.vb >

<Form1.vb>
Imports System.Threadin g

Add a TextBox - txtResult
Add a Button - btnStartThread

Private Sub Form1_Load(ByVa l sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load

Thread.CurrentT hread.Name = "Main"
Me.Text &= " - Thread Main #" & Thread.CurrentT hread.GetHashCo de End Sub

Private Sub btnStartThread_ Click(ByVal sender As Object, _ ByVal e As System.EventArg s) Handles btnStartThread. Click
' create a new worker...
Dim worker As New ThreadWorker()
worker.TextBox = txtResult

' spin up the thread...
worker.SpinUp()
End Sub
</Form1.vb>
.

Nov 20 '05 #6
Thanks Fergus...

There is a post where you dont have a helpfull post? :)

Crirus
"Fergus Cooney" <fi******@tesco .net> wrote in message
news:eu******** ******@TK2MSFTN GP12.phx.gbl...
Hi Frank,

I use OE too, so the attachment's fine.
Here's Crirus's code.

Regards,
Fergus

ps. This uses a TextBox for demonstation which is fine here, but is not the recommended way to interact with UI Controls. For that you need to call
oControl.BeginI nvoke.

=============== =============== =============
<ThreadWorker.v b>
Imports System.Threadin g

Public Class ThreadWorker

' members...
Public TextBox As TextBox
Private _thread As Thread

' Start - this method is the entry-point for the thread...
Private Sub Start()

' just set some text on the textbox...
TextBox.Text = "Hello, world from thread " & _
_thread.Name & " #" & _
Thread.CurrentT hread.GetHashCo de() & "!"
End Sub

' SpinUp - this method is called by the main application thread...
Public Sub SpinUp()

' create a thread start object that refers to our worker...
Dim threadStart As ThreadStart
threadStart = New ThreadStart(Add ressOf Me.Start)

' now, create the thread object and start it...
_thread = New Thread(threadSt art)
_thread.Name = "Worker"
_thread.Start()

End Sub

End Class
</ThreadWorker.vb >

<Form1.vb>
Imports System.Threadin g

Add a TextBox - txtResult
Add a Button - btnStartThread

Private Sub Form1_Load(ByVa l sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load

Thread.CurrentT hread.Name = "Main"
Me.Text &= " - Thread Main #" & Thread.CurrentT hread.GetHashCo de
End Sub

Private Sub btnStartThread_ Click(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles btnStartThread. Click

' create a new worker...
Dim worker As New ThreadWorker()
worker.TextBox = txtResult

' spin up the thread...
worker.SpinUp()
End Sub
</Form1.vb>

Nov 20 '05 #7
Hi Crirus,

ROFL. Fingers in many pies, but in some I'm the bad guy!! I'm not all
sweetness and light, much to the occasional annoyance of a couple of people
and permanent (perhaps not, that's a long time) distaste of a couple of
others.

But more friends than otherwise. ;-))

Regards,
Fergus
Nov 20 '05 #8

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

Similar topics

4
4560
by: Mike Read | last post by:
Hi I using Java and JDBC to connect to MS SQL server 2000 (using the MS drivers msbase,msutil and mssqlserver.jars). Sometimes it takes a long time for statement.executeQuery to return and start returning the resultset (full DB scan can take 30-40 minutes). Does anyone know if it's possible to interupt/halt the query before
6
3211
by: Dave Spencer | last post by:
Hi all, New to this group and to C# in general (experienced in MFC). Anyway I have a ListView and a foreach loop that is doing something to each item in the list and updating the list on the screen. I have a button on the screen that I'll call STOP that is supposed to stop the processing of the loop in midstream. I have a bool global variable call bStop. The OnClick for the stop button sets bStop to true. The loop checks the value...
1
1266
by: Dave | last post by:
How would I program an interupt. If I have two buttons on a form, one starts a loop and the other stops the loop. What code would I need to add? private void button1_Click(object sender, System.EventArgs e) { int a= 1; int b= 0; while (a != 0) {
2
2002
by: Gershon | last post by:
I have an ASP.NET/C# web application running against a SQL Server database using ADO.NET. Whenever there is a long-running database query, the web application hangs until the database query is complete. Even clicking the browser's stop button and clicking on other links within the web application fails. The only thing the user can do is close the browser and open up a new browser window. Is there any other way for a user to interupt a...
1
4645
by: ori | last post by:
Hi, I'm facing a problem when trying to continue normal execution flow within a HttpHandler ProcessRequest method. In my application we currently have a custom HttpHandler registered which validates a user against some Authentication method and then allows him to continue his request if successfully authenticated or denies him access if not. We use a handler to do this authentication and we'd like to continue normal execution if...
4
4389
by: Dennis Sjogren | last post by:
Greetings! First, I'm not 100% sure where to post this question. I use VB.NET for this project, but it's really a design question (a question on which method to use when solving this problem). In this medium sized (30 or so forms) application, our users have requested a more visual notification of when the client (this app) is communicating with the server, or for other lenghty processes. Disabling the current form and changing the...
0
1105
by: ld | last post by:
Hi, I have a lib that implements the custom actions for my setup. I would like to be able to interupt the setup if an error occured or if the user wants to cancel one of the forms that execute during my custom action. Calling the event RollBack does not cause the setup to be interupted. The only thing that partially work is to through an exception and not handle it in the lib, this forces the setup to be interupted but causes an automatic...
1
1500
by: sigamani | last post by:
how many interupt in embedded in c language
4
27982
by: sphinney | last post by:
Hi everyone. I'm creating an application inside Access 2007. The application will retrieve data from various locations on my company's network servers. Depending on the time of day, alignment of the planets, other unfathomable mysteries sometimes my company's network is very, very slow. I would like to provide the user of my application with a "Cancel" button on a form that will cancel/stop execution of the code (at whatever point it may...
0
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.