473,385 Members | 1,907 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,385 software developers and data experts.

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 1468
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*******@discussions.microsoft.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*******@discussions.microsoft.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.BeginInvoke.

===========================================
<ThreadWorker.vb>
Imports System.Threading

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.CurrentThread.GetHashCode() & "!"
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(AddressOf Me.Start)

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

End Sub

End Class
</ThreadWorker.vb>

<Form1.vb>
Imports System.Threading

Add a TextBox - txtResult
Add a Button - btnStartThread

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

Thread.CurrentThread.Name = "Main"
Me.Text &= " - Thread Main #" & Thread.CurrentThread.GetHashCode
End Sub

Private Sub btnStartThread_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) 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.BeginInvoke.

===========================================
<ThreadWorker.vb>
Imports System.Threading

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.CurrentThread.GetHashCode() & "!"
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(AddressOf Me.Start)

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

End Sub

End Class
</ThreadWorker.vb>

<Form1.vb>
Imports System.Threading

Add a TextBox - txtResult
Add a Button - btnStartThread

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

Thread.CurrentThread.Name = "Main"
Me.Text &= " - Thread Main #" & Thread.CurrentThread.GetHashCode End Sub

Private Sub btnStartThread_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) 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**************@TK2MSFTNGP12.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.BeginInvoke.

===========================================
<ThreadWorker.vb>
Imports System.Threading

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.CurrentThread.GetHashCode() & "!"
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(AddressOf Me.Start)

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

End Sub

End Class
</ThreadWorker.vb>

<Form1.vb>
Imports System.Threading

Add a TextBox - txtResult
Add a Button - btnStartThread

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

Thread.CurrentThread.Name = "Main"
Me.Text &= " - Thread Main #" & Thread.CurrentThread.GetHashCode
End Sub

Private Sub btnStartThread_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) 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
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...
6
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...
1
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,...
2
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...
1
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...
4
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). ...
0
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...
1
by: sigamani | last post by:
how many interupt in embedded in c language
4
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.