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

Simultaneous control of the gui

I'm creating an application that needs to go through over 2,000 loops
repeatedly.

However, the user interface is "locking up" while the processing is
happening.

Why is this happening, and how can I implement buttons to either pause or
stop the code?
Nov 21 '05 #1
8 1183
you might want to look into threads

"Richard Aubin" <rcaubin@safe-mailDOTnet> wrote in message
news:ey**************@TK2MSFTNGP10.phx.gbl...
I'm creating an application that needs to go through over 2,000 loops
repeatedly.

However, the user interface is "locking up" while the processing is
happening.

Why is this happening, and how can I implement buttons to either pause or
stop the code?

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004
Nov 21 '05 #2
Nak
Hi Richard,
I'm creating an application that needs to go through over 2,000 loops
repeatedly.
May I ask what the loop is performing?

There are a few ways to prevent lock ups, one way is to run the routine
in a separate thread, for example

Private cmythread as Threading.Thread

Private Sub startReading()
cmythread = New Threading.Thread(AddressOf stuff)
cmythread.IsBackground = True
Call cmythread.Start()
End Sub

Private Sub stuff()
'Any code in here is performed in a new thread, thus preventing your
main thread from being
'locked up!
End Sub

The above will initiate a new thread to perform the tasks in "stuff",
once the routine is ended the thread will end. Another way is to "yield" to
the operater at the end of each loop by using Application.DoEvents. But
this can cause strange effects in your application and also slow it down a
hell of a lot. But all in all it depends what you are doing in your loop.
However, the user interface is "locking up" while the processing is
happening.


Basically a "lock-up" occurs when your application cannot get enough
time to process windows messages as the time is being alloted elsewhere,
your intensive loop for example. The idea of placing an
"Application.DoEvents" statement at the end of each loop is to cause your
application to process any outstanding messages passed to it via the
operator.

Nick.
Nov 21 '05 #3
A simple solution would be to add Application.DoEvents in the loop.

hope this helps..
Imran.

"Richard Aubin" <rcaubin@safe-mailDOTnet> wrote in message
news:ey**************@TK2MSFTNGP10.phx.gbl...
I'm creating an application that needs to go through over 2,000 loops
repeatedly.

However, the user interface is "locking up" while the processing is
happening.

Why is this happening, and how can I implement buttons to either pause or
stop the code?

Nov 21 '05 #4
I'll see if I can make this a little more clear, but I think I'm getting the
jist of it.

The user enters a keyword to search through a ton of strings held in an
array.

I want to be able to have a cancel button on the same form to be accessible
if the operation is taking too long.

Will starting another thread allow me to do this efficiently?

Richard.
"Nak" <a@a.com> wrote in message
news:eJ**************@TK2MSFTNGP10.phx.gbl...
Hi Richard,
I'm creating an application that needs to go through over 2,000 loops
repeatedly.
May I ask what the loop is performing?

There are a few ways to prevent lock ups, one way is to run the

routine in a separate thread, for example

Private cmythread as Threading.Thread

Private Sub startReading()
cmythread = New Threading.Thread(AddressOf stuff)
cmythread.IsBackground = True
Call cmythread.Start()
End Sub

Private Sub stuff()
'Any code in here is performed in a new thread, thus preventing your
main thread from being
'locked up!
End Sub

The above will initiate a new thread to perform the tasks in "stuff",
once the routine is ended the thread will end. Another way is to "yield" to the operater at the end of each loop by using Application.DoEvents. But
this can cause strange effects in your application and also slow it down a
hell of a lot. But all in all it depends what you are doing in your loop.
However, the user interface is "locking up" while the processing is
happening.


Basically a "lock-up" occurs when your application cannot get enough
time to process windows messages as the time is being alloted elsewhere,
your intensive loop for example. The idea of placing an
"Application.DoEvents" statement at the end of each loop is to cause your
application to process any outstanding messages passed to it via the
operator.

Nick.

Nov 21 '05 #5
Nak
Hi Richard,
I'll see if I can make this a little more clear, but I think I'm getting the jist of it.

The user enters a keyword to search through a ton of strings held in an
array.


Right, what about using a HashTable,

Dim pop as new HashTable

pop.add("key","object") 'Add an object to the hastable, key can be
*any* object as can object.

pop.contains("key") 'Check the existance of "key" within the
hashtable, again, key can be *any* object

Hashtables are so much quicker to use than array's especially if you
would like to search for a specific entry, you will find that you can find a
specific object within a hashtable containing thousands upon thousands of
objects within milliseconds!

Are you just checking to see if the keyword matches a list of keywords?
Remember that you can add *any* object into the hashtable and have it
"associated" with the keyword so to speak, so lets say you have a specific
class which performs a certain task on a value,

Public Interface MyInterface

Function doStuff(Byval iValue as integer) as integer

End Interface

Public Class addOne
Implements MyInterface

Public Function doStuff(Byval iValue as integer) as integer implements
MyInterface.doStuff
Return(iValue + 1)
End Function

End Class

Public Class takeOne
Implements MyInterface

Public Function doStuff(Byval iValue as integer) as integer implements
MyInterface.doStuff
Return(iValue - 1)
End Function

End Class

Dim pop As New Hashtable()

pop.Add("addone", New addOne())
pop.Add("takeone", New takeOne())

Dim poo As Integer = 10

MessageBox.Show(CType(pop.Item("addone"), MyInterface).doStuff(poo))
MessageBox.Show(CType(pop.Item("takeone"), MyInterface).doStuff(poo))

I hope this helps!! :-)

Nick.


Nov 21 '05 #6
Nak
I Should have explained that a little also,

Using polymorphism you can create a generic interface for the action that
you want your "keyword" to perform. Then create a class for each "keyword"
and implement your own version of "dostuff", then you can bung loads of
different "functions" so to speak into a hashtable for lightning fast
access.

Anyway, any probs just yell!

Nick.

"Nak" <a@a.com> wrote in message
news:ed**************@tk2msftngp13.phx.gbl...
Hi Richard,
I'll see if I can make this a little more clear, but I think I'm getting the
jist of it.

The user enters a keyword to search through a ton of strings held in an
array.


Right, what about using a HashTable,

Dim pop as new HashTable

pop.add("key","object") 'Add an object to the hastable, key can be
*any* object as can object.

pop.contains("key") 'Check the existance of "key" within

the hashtable, again, key can be *any* object

Hashtables are so much quicker to use than array's especially if you
would like to search for a specific entry, you will find that you can find a specific object within a hashtable containing thousands upon thousands of
objects within milliseconds!

Are you just checking to see if the keyword matches a list of keywords? Remember that you can add *any* object into the hashtable and have it
"associated" with the keyword so to speak, so lets say you have a specific
class which performs a certain task on a value,

Public Interface MyInterface

Function doStuff(Byval iValue as integer) as integer

End Interface

Public Class addOne
Implements MyInterface

Public Function doStuff(Byval iValue as integer) as integer implements
MyInterface.doStuff
Return(iValue + 1)
End Function

End Class

Public Class takeOne
Implements MyInterface

Public Function doStuff(Byval iValue as integer) as integer implements
MyInterface.doStuff
Return(iValue - 1)
End Function

End Class

Dim pop As New Hashtable()

pop.Add("addone", New addOne())
pop.Add("takeone", New takeOne())

Dim poo As Integer = 10

MessageBox.Show(CType(pop.Item("addone"), MyInterface).doStuff(poo))
MessageBox.Show(CType(pop.Item("takeone"), MyInterface).doStuff(poo))

I hope this helps!! :-)

Nick.

Nov 21 '05 #7
* "Richard Aubin" <rcaubin@safe-mailDOTnet> scripsit:
I'm creating an application that needs to go through over 2,000 loops
repeatedly.

However, the user interface is "locking up" while the processing is
happening.

Why is this happening, and how can I implement buttons to either pause or
stop the code?


Call 'Application.DoEvents' every n iterations, or use multithreading:

Multithreading:

<URL:http://msdn.microsoft.com/library/en-us/dnforms/html/winforms06112002.asp>
<URL:http://msdn.microsoft.com/library/en-us/dnforms/html/winforms08162002.asp>
<URL:http://msdn.microsoft.com/library/en-us/dnforms/html/winforms01232003.asp>

<URL:http://www.devx.com/dotnet/Article/11358/>

<URL:http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsControlClassInvokeTopic.asp >

Multithreading in Visual Basic .NET (Visual Basic Language Concepts)
<URL:http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconthreadinginvisualbasic.asp>

Sample:

<URL:http://dotnet.mvps.org/dotnet/samples/filesystem/downloads/FileSystemEnumerator.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #8
Richard,

When you have predefined keys, than I think there cannot be any discussion
about that great idea from Nick.

However when your keywords can be spread all over the place than show us
your code. The method you use can be very important in that.

When you use only a simple regex it can be by instance often much more than
100 times slower than by using by instance a Visual Basic INSTR.

We did a test october last year (for which I used the counting method from
Nick)

In that test it was that for searching a string the most performance had the
Visual.Basic INSTR function. For a single characters it was the indexof I
thougth,

http://www.google.com/gr**********************************@reader20.wxs. nl

I hope this helps?

Cor
I'll see if I can make this a little more clear, but I think I'm getting the jist of it.

The user enters a keyword to search through a ton of strings held in an
array.

I want to be able to have a cancel button on the same form to be accessible if the operation is taking too long.

Will starting another thread allow me to do this efficiently?

Richard.
"Nak" <a@a.com> wrote in message
news:eJ**************@TK2MSFTNGP10.phx.gbl...
Hi Richard,
I'm creating an application that needs to go through over 2,000 loops
repeatedly.
May I ask what the loop is performing?

There are a few ways to prevent lock ups, one way is to run the

routine
in a separate thread, for example

Private cmythread as Threading.Thread

Private Sub startReading()
cmythread = New Threading.Thread(AddressOf stuff)
cmythread.IsBackground = True
Call cmythread.Start()
End Sub

Private Sub stuff()
'Any code in here is performed in a new thread, thus preventing your
main thread from being
'locked up!
End Sub

The above will initiate a new thread to perform the tasks in "stuff", once the routine is ended the thread will end. Another way is to "yield" to
the operater at the end of each loop by using Application.DoEvents. But
this can cause strange effects in your application and also slow it down

a hell of a lot. But all in all it depends what you are doing in your loop.
However, the user interface is "locking up" while the processing is
happening.


Basically a "lock-up" occurs when your application cannot get enough
time to process windows messages as the time is being alloted elsewhere,
your intensive loop for example. The idea of placing an
"Application.DoEvents" statement at the end of each loop is to cause your application to process any outstanding messages passed to it via the
operator.

Nick.


Nov 21 '05 #9

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

Similar topics

19
by: Claudio Grondi | last post by:
I would like to save time copying the same file (>6 GByte) to various different target storage media connected to the system via USB. Is there a (Python or other) tool able to help me to do...
1
by: slugger | last post by:
Hope this is not OT: I am running into some strange things whenever my ASP pages send out simultaneous requests to another ASP page which in turn gains access to a MySQL database using a DSNless...
6
by: Jimnbigd | last post by:
I want to write a game, and sounds will really add to it. Note that I would always make the sounds optional. I hate it when I go to a URL and unexpectedly get sounds or music. I have played...
1
by: Semaj | last post by:
Environment: DB2 8.1.4; Windows 2000 We are evaluating the feasibility of upgrading our production DB from 7.2 to 8.1. During this process we've encountered an error when starting our...
5
by: Dexter | last post by:
Hello all, I need all my developers work at a project simultaneous. How it is possible? I need a machine as web server? And how to configure the visual studio to all to work simultaneous? ...
12
by: Dan V. | last post by:
Since an ASP.NET/ADO.NET website is run on the server by a single "asp_net worker process", therefore doesn't that mean that even 50 simultaneous human users of the website would appear to the...
1
by: Simon | last post by:
Is there HTTP connection limit of 2 simultaneous connections in webservices? For example what hapens if you use webservices form ASP.NET web application? Presumably ASP.NET is webservices client to...
1
by: googlegroups | last post by:
Hello everyone, I need a new web server for our existing website and I don't want subscribe to the whole IIS way of doing things. I thought I would implement a custom web server using the new...
4
by: raylopez99 | last post by:
Compound question: first, and this is not easy, if there's a way to detect multiple simultaneous key presses in C# let me know (in the below code, keys c and d being pressed simultaneously or...
4
by: subhachu | last post by:
Hi, I would like to know, how to control the simultaneous downloads in PHP, say may be by trackin' from MySQL.... I need to allow only one IP to download a file... From my server... @ once.....
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.