Click here to Skip to main content
15,886,761 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr28-Sep-15 1:39
Benjamin.Buhr28-Sep-15 1:39 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen28-Sep-15 5:38
professionalEddy Vluggen28-Sep-15 5:38 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr28-Sep-15 22:49
Benjamin.Buhr28-Sep-15 22:49 
QuestionRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen29-Sep-15 1:25
professionalEddy Vluggen29-Sep-15 1:25 
AnswerRe: How to remain WPF Window always on top of all windows? Pin
Benjamin.Buhr14-Oct-15 0:37
Benjamin.Buhr14-Oct-15 0:37 
GeneralRe: How to remain WPF Window always on top of all windows? Pin
Eddy Vluggen15-Oct-15 4:38
professionalEddy Vluggen15-Oct-15 4:38 
QuestionMemory leak deterioration in performance in working with weight in rs232 Win-CE Pin
goldsoft21-Sep-15 21:20
goldsoft21-Sep-15 21:20 
AnswerRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
OriginalGriff21-Sep-15 21:40
mveOriginalGriff21-Sep-15 21:40 
For starters, you should never have to call in the garbage collector yourself: it only needs to be used when you start to run out of memory.

Second, that's really rather nasty code. The DataReceived event is started on a non-UI thread, as you know (or you wouldn't be Invoking the UI), but you are changing / using the value of SB on two threads, with no checking or locking to make sure that there isn't a problem. And you Invoke the UI thread even if there is no data to play with - and DataReceived can be fired for each character received, even if you have already removed them from the buffer.
You are also creating a new Font object (which is identical to the last) potentially for each character you receive, without any attempt to dispose of them. The GC will not do that, so Graphics Handles are being used up at a frightening rate - and these do not trigger the GC to do anything.
And there is a spurious ToString in there: Split returns an array of strings, so converting its constituent parts to a string is unnecessary.

Personally?
I'd have a background task processing the data with locking to prevent problems, and only invoke the bits which update the actual UI elements. I'd also use the same Font object for the label, and not change it at all.
And Application.DoEvents is a definite no-no!
I'd probably not use Split at all - it's not particularly efficient since it creates a lot of memory you aren't using. I'd look at IndexOf and SubString instead to "pull out" just the bit you are interested in. Even if I did use Split, you really, really need to check the number of array elements it returns: The DataReceived event doesn't wait for the end of your message before it "kicks in"...


[edit]Typos[/edit]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...


modified 22-Sep-15 5:06am.

GeneralRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
goldsoft21-Sep-15 23:04
goldsoft21-Sep-15 23:04 
GeneralRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
Pete O'Hanlon21-Sep-15 23:08
mvePete O'Hanlon21-Sep-15 23:08 
GeneralRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
OriginalGriff21-Sep-15 23:30
mveOriginalGriff21-Sep-15 23:30 
GeneralRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
goldsoft23-Sep-15 22:28
goldsoft23-Sep-15 22:28 
GeneralRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
OriginalGriff23-Sep-15 22:37
mveOriginalGriff23-Sep-15 22:37 
GeneralRe: Memory leak deterioration in performance in working with weight in rs232 Win-CE Pin
goldsoft24-Sep-15 0:49
goldsoft24-Sep-15 0:49 
QuestionI want to perform a similiar operation on 100 VMs open in my Remote Desktop Connection Manager; Can I Automate it? Pin
AshiSh RaNa21-Sep-15 19:35
AshiSh RaNa21-Sep-15 19:35 
AnswerRe: I want to perform a similiar operation on 100 VMs open in my Remote Desktop Connection Manager; Can I Automate it? Pin
Pete O'Hanlon21-Sep-15 21:06
mvePete O'Hanlon21-Sep-15 21:06 
GeneralRe: I want to perform a similiar operation on 100 VMs open in my Remote Desktop Connection Manager; Can I Automate it? Pin
AshiSh RaNa21-Sep-15 23:51
AshiSh RaNa21-Sep-15 23:51 
QuestionHow to get the user defined method Pin
vijay kumar20-Sep-15 23:27
vijay kumar20-Sep-15 23:27 
AnswerRe: How to get the user defined method Pin
Eddy Vluggen20-Sep-15 23:48
professionalEddy Vluggen20-Sep-15 23:48 
GeneralRe: How to get the user defined method Pin
OriginalGriff21-Sep-15 0:51
mveOriginalGriff21-Sep-15 0:51 
GeneralRe: How to get the user defined method Pin
vijay kumar21-Sep-15 20:33
vijay kumar21-Sep-15 20:33 
AnswerRe: How to get the user defined method PinPopular
BillWoodruff21-Sep-15 2:48
professionalBillWoodruff21-Sep-15 2:48 
GeneralRe: How to get the user defined method Pin
Eddy Vluggen21-Sep-15 5:22
professionalEddy Vluggen21-Sep-15 5:22 
GeneralRe: How to get the user defined method Pin
vijay kumar21-Sep-15 20:32
vijay kumar21-Sep-15 20:32 
QuestionWrite an algorithm to add and multiply two large integers, which cannot be represented by built-in types Pin
Nadeem Shaikh20-Sep-15 5:51
Nadeem Shaikh20-Sep-15 5:51 

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.