Click here to Skip to main content
15,913,773 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Problem with Form and network access [modified] Pin
Cory Kimble24-Mar-08 10:02
Cory Kimble24-Mar-08 10:02 
GeneralRe: Problem with Form and network access Pin
Dave Kreskowiak24-Mar-08 10:43
mveDave Kreskowiak24-Mar-08 10:43 
GeneralRe: Problem with Form and network access Pin
Luc Pattyn24-Mar-08 9:59
sitebuilderLuc Pattyn24-Mar-08 9:59 
GeneralRe: Problem with Form and network access Pin
Cory Kimble25-Mar-08 3:34
Cory Kimble25-Mar-08 3:34 
GeneralRe: Problem with Form and network access Pin
Dave Kreskowiak25-Mar-08 4:08
mveDave Kreskowiak25-Mar-08 4:08 
GeneralRe: Problem with Form and network access Pin
Cory Kimble25-Mar-08 5:52
Cory Kimble25-Mar-08 5:52 
GeneralRe: Problem with Form and network access Pin
Dave Kreskowiak26-Mar-08 13:31
mveDave Kreskowiak26-Mar-08 13:31 
GeneralRe: Problem with Form and network access Pin
Luc Pattyn25-Mar-08 4:12
sitebuilderLuc Pattyn25-Mar-08 4:12 
Hi Cory,

Your code is not very clear; here are my assumptions:
1. the files refered to in the lines frmsr = New StreamReader("program files\steidingerfoodsce\localship.txt")
and dim swship as streamwriter = New StreamWriter(localShipFile, False)
are the same
2. sub ReWriteSHIPFile intends to delete the original file.

Under those assumptions I see two potential problems:

1. you do close the streams frmsr (and frmsw) but you fail to dispose of them, although the
documentation says one should dispose of streams. (In fact one should dispose of any class instance
that has a public dispose method). Failing to do so is likely to have negative effects, in this
case I expect the underlying file system does not get cleaned up until the Finalize method is
executed (either by calling dispose explicitly, or by forcing a garbage collection, which happens
to occur when you minimize your form).

2. other processes may have the same file temporarily open (without you being aware); that happens
for fresh files when you have disk indexing enabled, or a gready antivirus program.
in these cases, you should attempt say 5 times in a loop, with 1 second intervals to solve almost
all of it.

Further remarks:

1.
you should avoid similar lines of code, they will lead to mistakes in the end (when you change one
and forget to change the other). Example: swship.WriteLine(frmShip.cmbobxLocation.Text + "," + frmShip.txtbxScanID.Text + "," + frmShip.cmbobxBuyer.Text + "," + dt.ToString("d"))
Solution: calculate the text line once, and (re)use it where ever you need it.

2.
you should avoid magic constants in your code; here "program files\steidingerfoodsce\localship.txt"
should be defined once, at the start of your program, in the initialization code, not in the middle of some
method. And I suspect you already have the variable localShipFile to point to it, so use it consistently.

3.
not sure you should store application data files under "program files". Some Windows versions, and/or some
installations won't let your app write anything there.

4.
I don't like the catch blocks that catch an exception and then ignore it, i.e. only the change-in-flow is used,
not the actual exception. On the other hand, MessageBox.Show(ex.ToString) is excellent; most
programmers use Message or so and miss most of the exception text...

5.
the sequence Flush() followed by Close() is overkill; AFAIK every Close() implies a Flush(), flush is useful
only if you do not intend to close right away but want to make sure the data so far got out to disk anyway.

6.
If the aim of ReWriteSHIPFile() is to delete a possibly existing file, there are better ways to do that.
And remember trying 5 times with 1 sec intervals (as Windows Explorer does, but no single API function offers).

Regards,

Luc Pattyn [Forum Guidelines] [My Articles]

This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.


GeneralRe: Problem with Form and network access Pin
Cory Kimble25-Mar-08 6:00
Cory Kimble25-Mar-08 6:00 
QuestionCan we launch EXCEL.EXE with an existed .xls file? Pin
ATC24-Mar-08 3:47
ATC24-Mar-08 3:47 
AnswerRe: Can we launch EXCEL.EXE with an existed .xls file? Pin
Dave Kreskowiak24-Mar-08 4:14
mveDave Kreskowiak24-Mar-08 4:14 
GeneralRe: Can we launch EXCEL.EXE with an existed .xls file? Pin
ATC24-Mar-08 4:39
ATC24-Mar-08 4:39 
GeneralRe: Can we launch EXCEL.EXE with an existed .xls file? Pin
Dave Kreskowiak24-Mar-08 5:40
mveDave Kreskowiak24-Mar-08 5:40 
GeneralRe: Can we launch EXCEL.EXE with an existed .xls file? Pin
ATC24-Mar-08 6:23
ATC24-Mar-08 6:23 
Questionupdate problem Pin
habibah23-Mar-08 23:20
habibah23-Mar-08 23:20 
GeneralRe: update problem Pin
Dave Kreskowiak24-Mar-08 4:13
mveDave Kreskowiak24-Mar-08 4:13 
QuestionRe: update problem Pin
habibah24-Mar-08 22:31
habibah24-Mar-08 22:31 
GeneralRe: update problem Pin
Dave Kreskowiak26-Mar-08 13:28
mveDave Kreskowiak26-Mar-08 13:28 
GeneralRe: update problem Pin
Vimalsoft(Pty) Ltd24-Mar-08 7:24
professionalVimalsoft(Pty) Ltd24-Mar-08 7:24 
Generalplease! i badly need help... Pin
sakhura_3123-Mar-08 22:56
sakhura_3123-Mar-08 22:56 
GeneralRe: please! i badly need help... Pin
Dave Kreskowiak24-Mar-08 3:55
mveDave Kreskowiak24-Mar-08 3:55 
GeneralRe: please! i badly need help... Pin
Christian Graus24-Mar-08 10:26
protectorChristian Graus24-Mar-08 10:26 
QuestionDeploy Crystal Report in Remote Server Pin
Abdul Rahman Hamidy23-Mar-08 22:35
Abdul Rahman Hamidy23-Mar-08 22:35 
GeneralRe: Deploy Crystal Report in Remote Server Pin
Dave Kreskowiak24-Mar-08 4:12
mveDave Kreskowiak24-Mar-08 4:12 
GeneralRe: Deploy Crystal Report in Remote Server Pin
Kschuler24-Mar-08 4:51
Kschuler24-Mar-08 4: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.