Program Crash with File IO Access

S

Sarah

Hello,

I am running some code every 10 seconds to copy a file from a DOS server
over a Lantastic network. The problem is that when the DOS server is
restarted (it has to some times), my program crashes and reboots Windows. My
VB.Net Program is running on a Windows XP system using Lantastic 8.0 to
access the DOS server. How can I write the code so that if the DOS server
that the file is being copied from goes down, my VB.Net program continues to
run without crashing? Code is running in a timer control tick event and is
included below.

=========

Try

If File.Exists("\\Server1\Files\Data1.dbf") Then

Try
File.Copy(("\\Server1\Files\Data1.dbf",
"C:\Data\tblData.dbf", True)
Catch
'Do Nothing
End Try

End If

Catch

'Do Nothing

End Try
 
C

Cor Ligthert

Sarah,

The least thing you can do is changing in your code this

\\\
If File.Exists("\\Server1\Files\Data1.dbf") Then
Try
File.Copy(("\\Server1\Files\Data1.dbf",
"C:\Data\tblData.dbf", True)
Catch ex as exception
Messagebox.show(ex.tostring)
End Try
Else
messagebox.show("file does not exist)
End if
///

Making empty catch blocks is the worst thing you can do.

I hope this helps?

Cor
 
S

Sarah

The least thing you can do is changing in your code this

\\\
If File.Exists("\\Server1\Files\Data1.dbf") Then
Try
File.Copy(("\\Server1\Files\Data1.dbf",
"C:\Data\tblData.dbf", True)
Catch ex as exception
Messagebox.show(ex.tostring)
End Try
Else
messagebox.show("file does not exist)
End if
///

Making empty catch blocks is the worst thing you can do.

Right now I have the Catch change the timer to a longer tick just to give it
some time before trying it again. I put the file.exists in a try/catch block
as well because I just can't stop the program from doing a full crash and
rebooting the system right away when the DOS server is restarted. The file
check/copy process is happening every 10 seconds so is there any other way
to do the check/copy so that it will not crash? Hope someone has some ideas.
 
C

Cor Ligthert

Sarah,

Than maybe you have your problem directly. The catch is only slow the first
time it is used.

However you would surely not use that in my opinion for what you tell you
want to archieve.

I hope this helps?

Cor
 
S

Sarah

Than maybe you have your problem directly. The catch is only slow the first
time it is used.

What I said is when a try block enters a catch exception I have it so that
the timer tick does not check as frequently - i.e. not check every 10
seconds. That has nothing to do with the crash problem. You asked that a
catch exception should not be empty - which, I'm not sure should be a
problem - so, I mentioned what I have put there. (i.e. putting a msgbox in a
catch exception - that does not prevent the system from crashing).

I'm still looking for code that would not crash when the DOS server goes
down (i.e. is in a restart or is off).
 
C

Cor Ligthert

Sarah,
What I said is when a try block enters a catch exception I have it so that
the timer tick does not check as frequently - i.e. not check every 10
seconds. That has nothing to do with the crash problem. You asked that a
catch exception should not be empty - which, I'm not sure should be a
problem - so, I mentioned what I have put there. (i.e. putting a msgbox in
a
catch exception - that does not prevent the system from crashing).
What prevents it than?

Cor
 
S

Sarah

That's my question! That's why I provided the code and am asking someone who
can help me figure it all out.
 
C

Cor Ligthert

Sarah,
That's my question! That's why I provided the code and am asking someone
who
can help me figure it all out.
Therefore I wrote to set the messagebox in that catch, than is probably
better showed what gives the error.

The code you now have showed is something I would not even type in a message
so bad is it.
(The messagebox is only a timely part for a better error resolving
procedure)

Cor
 
S

Sarah

Cor, please don't respond to any of my posts any more - you either always
seem to misunderstand my questions or post unhelpful comments. Thank you.
 
C

Cor Ligthert

No problem at all, I hope for you that someone find a solution for you,
however mostly when I give a wrong answers someone else corrects me, what is
normal in a newsgroup.

I saw never corrections with your questions.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top