473,666 Members | 2,114 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_DataRece ived( object sender,
System.IO.Ports .SerialDataRece ivedEventArgs e )

{

int number_of_bytes = seriel.BytesToR ead;

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

uart.rx_wr_inde x += 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_pacakg e(x); // send the data..

while ( go_no_go_flag == 0 )

{

application.DoE vents();

}

if ( go_no_go_flag == 2 ) // NO GO

goto try_again;

}

My problem is that the data is comming in correctly but the
application.DoE vents(); 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_packag e !

What can i do to speed it up?

Best regards

Lasse Madsen


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

see this component - BackgroundWorke r 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_DataRece ived( object sender,
System.IO.Ports .SerialDataRece ivedEventArgs e )

{

int number_of_bytes = seriel.BytesToR ead;

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

uart.rx_wr_inde x += 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_pacakg e(x); // send the data..

while ( go_no_go_flag == 0 )

{

application.DoE vents();

}

if ( go_no_go_flag == 2 ) // NO GO

goto try_again;

}

My problem is that the data is comming in correctly but the
application.DoE vents(); 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_packag e !

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.DoE vents(); 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_packag e !


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
5262
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 the moment. I'd be *very* grateful if people with any interest in multi-threading would read it (even just bits of it - it's somewhat long to go through the whole thing!) to check for accuracy, effectiveness of examples, etc. Feel free to mail...
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 error appears at the following statment sqlda.Fill(dtMessages); During an infinit loopp
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 base class for the worker class, and made up some functions/delegates to handle the invoke stuff for the UI and that was fine for a prototype. I rewrote this chunk, broke things out into different classes - but the threading is still the same - and...
4
6570
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 page completely loads. This article addresses the above issues for OnBeforeNavigate2 event: http://www.codeproject.com/buglist/iefix.asp?df=100&forumid=13326&exp=0&select=408890. I changed it to work with DocumentComplete(), which seems to work well...
5
2036
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 connects to the desktop via ActiveSync then a separate thread is spawned. In addition to the main desktop app window I also have a Notification form that appears in the lower right of the screen and provides feedback to the user about what is...
2
1319
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 written to by different threads in my example. It works fine so I'm wondering if anyone can tell me what I need to watch out for with respect to Forms and threading? For what it's worth, here is my short proggie: Private Sub SomeTask() ' This...
5
1528
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 mySub(IPAddress(i)) Next And inside mySub, I'm initializing a new network connection (SFTP if you
8
2442
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 automating. Because there are many fast timers on each, I have placed each one of these forms in their own thread by using the following code: Dim NewForm As New frmFormName Dim NewThread As System.Threading.Thread NewThread = New...
0
1459
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 System.Diagnostics Imports System.Threading Public Class Form1
0
8356
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,...
0
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
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
6198
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
5664
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
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.