473,507 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threading / DoEvents !?

Hi all,

I have an application where i need to receive some data through the C#
seriel port component.

My receive event and uart class which holds the receive buffer etc. looks
like this:
private void seriel_DataReceived( object sender,
System.IO.Ports.SerialDataReceivedEventArgs e )

{

int number_of_bytes = seriel.BytesToRead;

seriel.Read (uart.buffer,uart.rx_wr_index,number_of_bytes);

uart.rx_wr_index += number_of_bytes;

}

class uart

{

static public byte[] buffer = new byte[4096];

static public int rx_wr_index=0;

}

In my application a timer looks at the buffer every 1mS and determines if we
have a "GO / NO GO" situration and asserts a flag correspondantly.

In my application i have a button ... if i press the button i transmit 118
packages of 10 bytes each to another computer over the serial port at 38400
baud ... every time a package is received by the other computer it sends a
"GO / NO GO" response telling me to either try again or proceed with the
next package.

The code could look like this where the go_no_go_flag is updated in the 1mS
timer looking at the buffer...

for ( x = 0 ; x < 118 ; x++ )

{

try_again:

go_no_go_flag = 0;

transmit_pacakge(x); // send the data..

while ( go_no_go_flag == 0 )

{

application.DoEvents();

}

if ( go_no_go_flag == 2 ) // NO GO

goto try_again;

}

My problem is that the data is comming in correctly but the
application.DoEvents(); takes ALOT of time so it slows my application down

In an old DOS program i've written some years ago the entire transmission
took under 1 second but now it takes roughly half a second pr
transmit_package !

What can i do to speed it up?

Best regards

Lasse Madsen


Jun 14 '06 #1
3 1916
you can put the logic for data trasnfer in separate thread and see if
it is faster

see this component - BackgroundWorker Class

http://msdn2.microsoft.com/en-us/sys...undworker.aspx

hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com

Lasse Madsen wrote:
Hi all,

I have an application where i need to receive some data through the C#
seriel port component.

My receive event and uart class which holds the receive buffer etc. looks
like this:
private void seriel_DataReceived( object sender,
System.IO.Ports.SerialDataReceivedEventArgs e )

{

int number_of_bytes = seriel.BytesToRead;

seriel.Read (uart.buffer,uart.rx_wr_index,number_of_bytes);

uart.rx_wr_index += number_of_bytes;

}

class uart

{

static public byte[] buffer = new byte[4096];

static public int rx_wr_index=0;

}

In my application a timer looks at the buffer every 1mS and determines if we
have a "GO / NO GO" situration and asserts a flag correspondantly.

In my application i have a button ... if i press the button i transmit 118
packages of 10 bytes each to another computer over the serial port at 38400
baud ... every time a package is received by the other computer it sends a
"GO / NO GO" response telling me to either try again or proceed with the
next package.

The code could look like this where the go_no_go_flag is updated in the 1mS
timer looking at the buffer...

for ( x = 0 ; x < 118 ; x++ )

{

try_again:

go_no_go_flag = 0;

transmit_pacakge(x); // send the data..

while ( go_no_go_flag == 0 )

{

application.DoEvents();

}

if ( go_no_go_flag == 2 ) // NO GO

goto try_again;

}

My problem is that the data is comming in correctly but the
application.DoEvents(); takes ALOT of time so it slows my application down

In an old DOS program i've written some years ago the entire transmission
took under 1 second but now it takes roughly half a second pr
transmit_package !

What can i do to speed it up?

Best regards

Lasse Madsen


Jun 14 '06 #2

My problem is that the data is comming in correctly but the
application.DoEvents(); takes ALOT of time so it slows my application down
Why are you using DoEvents?

Do all the connection stuff in a background thread. You can then update the
UI using Control.Invoke

calling DoEvents is a risky proposition, if you look in the archives you
will see lot of persons discouraging its use
In an old DOS program i've written some years ago the entire transmission
took under 1 second but now it takes roughly half a second pr
transmit_package !


How r u sending them?
the framework does not have a serial component, what r u using?

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jun 14 '06 #3
Hi Ignacio,
Why are you using DoEvents?
If i just do:

while ( go_no_go_flag == 0 );

my program freezes
Do all the connection stuff in a background thread. You can then update
the UI using Control.Invoke
I've never tried this.
calling DoEvents is a risky proposition, if you look in the archives you
will see lot of persons discouraging its use
Okay I will look into this.
How r u sending them?
the framework does not have a serial component, what r u using?


The latest framework (2.0) and C# express 2005 has a serial component thats
the one I'm using.

Best regards
Lasse Madsen
Jun 14 '06 #4

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

Similar topics

77
5208
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
3
539
by: Suhail Salman | last post by:
Dear All, i got the following error message in an applications that opens 13 threads and all of them calling a stored procedure which retreieves data from SQLServer and fills them to a table the...
13
371
by: RCS | last post by:
I have a UI that needs a couple of threads to do some significant processing on a couple of different forms - and while it's at it, update the UI (set textboxes, fill in listviews). I created a...
4
6563
by: Brett | last post by:
Say I open an IE window and call the Navigate() method. A web page opens. I use a delegate to capture the DocumentComplete and NavigateComplete2 events. However, they fire slightly before the...
5
2033
by: Robert W. | last post by:
I'm creating a WinForms app that will act as a companion (think administrator functionality) to a Pocket PC app. Generally the WinForms app works under just the UI thread. But if a Pocket PC...
2
1312
by: Tyson Ackland | last post by:
I have written a very simple threading proggie in an attempt to teach myself threading. I have seen it referred to in articles that Forms are not thread safe. My form has two labels which are...
5
1520
by: OpticTygre | last post by:
Heheh...I've got lots of questions today. If I have a loop that calls the same subroutine several times (that subroutine may be processor and network intensive): For i = 1 to 100 Call...
8
2429
by: Luc | last post by:
Hi, I am writing software to automate some testing. I have one main form to set up the tests, and once this is complete, I open 4 identical forms to monitor each different device that I am...
0
1440
by: SyGC | last post by:
Hi Guys, I have used Threading for Network.Ping to continuously ping an IP address if ping is successful Image A is displayed if not Image B. The code is as follows: Imports System Imports...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7111
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...
0
7319
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,...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7031
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...
0
5623
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,...
1
5042
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...
0
4702
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...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.