Click here to Skip to main content
15,890,670 members
Home / Discussions / C#
   

C#

 
QuestionHow to design? [modified] Pin
konglx sir9-Nov-09 14:47
konglx sir9-Nov-09 14:47 
AnswerRe: How to design? Pin
Christian Graus9-Nov-09 15:23
protectorChristian Graus9-Nov-09 15:23 
AnswerRe: How to design? Pin
PIEBALDconsult9-Nov-09 15:37
mvePIEBALDconsult9-Nov-09 15:37 
QuestionHow to call List[int] in other class [modified] Pin
laurisp9-Nov-09 13:57
laurisp9-Nov-09 13:57 
AnswerRe: How to call List[int] in other class Pin
Julianne_juju9-Nov-09 19:19
Julianne_juju9-Nov-09 19:19 
GeneralRe: How to call List[int] in other class Pin
laurisp9-Nov-09 21:29
laurisp9-Nov-09 21:29 
Questionnullrefererence exception Pin
hobbsjas9-Nov-09 13:31
hobbsjas9-Nov-09 13:31 
AnswerRe: nullrefererence exception Pin
Luc Pattyn9-Nov-09 14:33
sitebuilderLuc Pattyn9-Nov-09 14:33 
Hi,

I see two errors:

1.
your DoWork() method contains accesses to toolStripStatusLabel1.Text which it shouldn't. AFAIK (documentation doesn't contain this) all GUI parts, not just Controls, are untouchable by another than the main thread. You could read this[^] for more; I believe ToopStrip parts need the same approach; however they don't offer InvokeRequired/Invoke, so you would have to borrow another Control on the same Form (or the Form itself).

This would be sufficient to explain most erratic behavior your app may show, especially regarding the GUI. It probably is sufficient to cause the problem you're having, however only fixing and testing will tell.

2.
in while ((inFile.Read(buffer, 0, lineSize)) > 0) the Read method returns the number of bytes read, which you test for non-zero, but you don't otherwise use it; you really should store the value in a variable and use that instead of linesize in outFile.Write(buffer, 0, lineSize); as the value may be different, especially at the end of the file.


I also have several comments:

3.
I think a foreach would be much more elegant than while (cnt < src.Length && src[cnt] != null)

4.
when the destination file does not exist, you create a dummy one first; I see no use for that.

5.
you are reporting progress inside your copy loop; that will probably slow down the operation npticeably; I suggest you display the sizes in MB, not KB, and only update the GUI when the number has changed.

6.
you have some Flush-and-Close sequences; they don't make much sense, Close() implies Flush().

7.
you don't create the destination folder; if it does not exist, your app will fail copying files to it. A simple Directory.Create() would do, no need to test for existence. You must calculate the path though. The Path class has methods for that.

8.
I saw an empty catch block; that is a very bad idea as it hides potential problems. You should only catch what you can handle (i.e. solve) and leave the rest to the caller; alternatively, you should log the problem, but never let it disappear without treatment.

Smile | :)

Luc Pattyn

I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


GeneralRe: nullrefererence exception Pin
hobbsjas9-Nov-09 15:26
hobbsjas9-Nov-09 15:26 
GeneralRe: nullrefererence exception Pin
Luc Pattyn9-Nov-09 15:31
sitebuilderLuc Pattyn9-Nov-09 15:31 
GeneralRe: nullrefererence exception Pin
hobbsjas9-Nov-09 15:53
hobbsjas9-Nov-09 15:53 
GeneralRe: nullrefererence exception Pin
N a v a n e e t h9-Nov-09 16:02
N a v a n e e t h9-Nov-09 16:02 
GeneralRe: nullrefererence exception Pin
Luc Pattyn9-Nov-09 16:05
sitebuilderLuc Pattyn9-Nov-09 16:05 
GeneralRe: nullrefererence exception Pin
N a v a n e e t h9-Nov-09 15:59
N a v a n e e t h9-Nov-09 15:59 
GeneralRe: nullrefererence exception Pin
hobbsjas10-Nov-09 9:25
hobbsjas10-Nov-09 9:25 
QuestionInconsistent accessibility: property type is less accessible than property Pin
Kevin Marois9-Nov-09 13:28
professionalKevin Marois9-Nov-09 13:28 
AnswerRe: Inconsistent accessibility: property type is less accessible than property Pin
J$9-Nov-09 13:36
J$9-Nov-09 13:36 
GeneralRe: Inconsistent accessibility: property type is less accessible than property Pin
Kevin Marois9-Nov-09 13:49
professionalKevin Marois9-Nov-09 13:49 
GeneralRe: Inconsistent accessibility: property type is less accessible than property Pin
Luc Pattyn9-Nov-09 13:56
sitebuilderLuc Pattyn9-Nov-09 13:56 
QuestionWin32 Message Hooks and/or Legitimate Code Injection Pin
cymblicity9-Nov-09 12:54
cymblicity9-Nov-09 12:54 
AnswerRe: Win32 Message Hooks and/or Legitimate Code Injection Pin
Luc Pattyn9-Nov-09 15:28
sitebuilderLuc Pattyn9-Nov-09 15:28 
Questionhow can i calculate shortest path between neurons in artifical neural network graph? Pin
karayel_kara9-Nov-09 12:32
karayel_kara9-Nov-09 12:32 
QuestionC# subject not correct form because of shift+enter Pin
Jacob Dixon9-Nov-09 10:45
Jacob Dixon9-Nov-09 10:45 
AnswerRe: C# subject not correct form because of shift+enter Pin
Abhishek Sur9-Nov-09 10:48
professionalAbhishek Sur9-Nov-09 10:48 
GeneralRe: C# subject not correct form because of shift+enter Pin
Jacob Dixon9-Nov-09 10:55
Jacob Dixon9-Nov-09 10:55 

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.