Click here to Skip to main content
15,922,894 members
Home / Discussions / C#
   

C#

 
GeneralRe: Issue with running .exe(compiled in 34 bit) in window7 64bit enviornment Pin
Alan N7-Jun-10 3:58
Alan N7-Jun-10 3:58 
QuestionNUnit and testing in Web Developer 2008 Express Pin
Bart Van Eyndhoven7-Jun-10 0:22
Bart Van Eyndhoven7-Jun-10 0:22 
QuestionInstall windows Service from ClickOnce Deployment Pin
Abdul Rahman Hamidy7-Jun-10 0:04
Abdul Rahman Hamidy7-Jun-10 0:04 
QuestionChild Form From its parent form Pin
Enobong Adahada6-Jun-10 22:05
Enobong Adahada6-Jun-10 22:05 
AnswerRe: Child Form From its parent form Pin
Łukasz Nowakowski6-Jun-10 22:22
Łukasz Nowakowski6-Jun-10 22:22 
AnswerRe: Child Form From its parent form Pin
Anshul R8-Jun-10 20:33
Anshul R8-Jun-10 20:33 
QuestionMultithreading Pin
peropata6-Jun-10 21:20
peropata6-Jun-10 21:20 
AnswerRe: Multithreading Pin
Luc Pattyn7-Jun-10 1:01
sitebuilderLuc Pattyn7-Jun-10 1:01 
QuestionSerial number in installer. Pin
MayukhSen6-Jun-10 20:52
MayukhSen6-Jun-10 20:52 
AnswerRe: Serial number in installer. Pin
Hristo-Bojilov6-Jun-10 21:24
Hristo-Bojilov6-Jun-10 21:24 
QuestionPDF to Tiff through C# Pin
mehrdadc486-Jun-10 18:24
mehrdadc486-Jun-10 18:24 
AnswerRe: PDF to Tiff through C# Pin
Abhinav S6-Jun-10 19:01
Abhinav S6-Jun-10 19:01 
QuestionOtions to store settings of application Pin
Hum Dum6-Jun-10 17:49
Hum Dum6-Jun-10 17:49 
AnswerRe: Otions to store settings of application Pin
Łukasz Nowakowski6-Jun-10 21:25
Łukasz Nowakowski6-Jun-10 21:25 
AnswerRe: Otions to store settings of application Pin
Peace ON6-Jun-10 22:24
Peace ON6-Jun-10 22:24 
AnswerRe: Otions to store settings of application Pin
Johnny J.6-Jun-10 22:31
professionalJohnny J.6-Jun-10 22:31 
AnswerRe: Otions to store settings of application Pin
PIEBALDconsult7-Jun-10 2:40
mvePIEBALDconsult7-Jun-10 2:40 
Questionflickers with draw plots from serial port ? Pin
Honeyboy_206-Jun-10 16:40
Honeyboy_206-Jun-10 16:40 
AnswerRe: flickers with draw plots from serial port ? Pin
Luc Pattyn6-Jun-10 16:57
sitebuilderLuc Pattyn6-Jun-10 16:57 
GeneralRe: flickers with draw plots from serial port ? Pin
Honeyboy_206-Jun-10 17:09
Honeyboy_206-Jun-10 17:09 
GeneralRe: flickers with draw plots from serial port ? Pin
Luc Pattyn6-Jun-10 17:19
sitebuilderLuc Pattyn6-Jun-10 17:19 
GeneralRe: flickers with draw plots from serial port ? Pin
Honeyboy_208-Jun-10 5:24
Honeyboy_208-Jun-10 5:24 
GeneralRe: flickers with draw plots from serial port ? Pin
Ravi Bhavnani6-Jun-10 17:30
professionalRavi Bhavnani6-Jun-10 17:30 
GeneralRe: flickers with draw plots from serial port ? Pin
Honeyboy_207-Jun-10 5:19
Honeyboy_207-Jun-10 5:19 
GeneralRe: flickers with draw plots from serial port ? Pin
Luc Pattyn8-Jun-10 6:28
sitebuilderLuc Pattyn8-Jun-10 6:28 
Hi,

I've been trying to read some of that code, which you made very hard by not using PRE tags. PRE tags exist for preserving formatting, mainly indentation, which facilitates seeing the structure of it all. So whatever you do in future, use PRE tags. You could even still edit your existing message and put PRE tags around its code.

The code itself looks horrible too. Here are some comments, the list is not complete:

1.
using Exception.Message rather than Exception.ToString() is stupid, as the latter offers much more information, making debugging a lot easier.

2.
You have a DataReceived event handler (fine), but all it does is use Invoke to force a delegate to execute on the GUI thread, so it actually is your GUI thread that will read all bytes from the serial port and interpret them. That is not smart, as it has no relation with the GUI at all. You should deal with the serial data in a handler (or a separate thread) and only invoke towards the GUI thread at the very moment you want to update the GUI.

3.
you read all serial port data one byte at a time; why not use SerialPort.Read(byte[] buffer, int offset, int count) to read all available data at once, then process it?

4.
you have lots of unnecessary conversions, from bytes to strings to ints and back. As your data is binary (I assume so, since you are reading bytes right now), why not always deal with it as bytes; and possibly once turning it into a string for displaying it if necessary.

5.
Get rid of those silly Conversion.Hex calls; they reek like Basic. If at all necessary, simply use byte.ToString("X2")

6.
I skipped some code, then saw a Paint method, with lots of mistakes.
A. use the Graphics you get from PaintEventArgs, don't create your own
B. don't call Invalidate() or Refresh() in a Paint handler. It is terribly wrong.
C. Avoid calling methods such as Math.Cos in a paint handler; you should have done that calculation beforehand and store it in your objects.
D. Dispose of the garbage you create; e.g. the pen


Conclusion: it is an abominable mess; I don't want to have another look at it, it should be binned and started all over.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

I only read formatted code with indentation, so please use PRE tags for code snippets.

I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.