Setting up delay for function call

A

Aryan

Hi,
I have function which creates two xml files,after creation these
xml's, I am calling another function which reads these xml files. Now
this function is causing exception becuase data has not been read from
xml file and stored in using by other control. I am looking out for
some workaround by which i can delay the calls for reading out these
xml files.

Thanks in advance
Manoj
 
M

michaelkb

You might try executing the delayed action through a seperate thread.
Example:

Thread _ExceededThread;
ThreadStart _ExceededThreadStart;

private void startDelayedTaskProcess()
{
_ExceededThreadStart = new ThreadStart(DelayedTaskStarter);
_ExceededThread = new Thread(_ExceededThreadStart);
_ExceededThread.Start();
}

private static void DelayedTaskStarter()
{
Thread.Sleep(20000);
DoDelayedTasks();
}

There might be a better way... but this is the only way I know of right
now...
 
S

S. Justin Gengo

Manoj,

One way would be to create the files asynchronously using a new thread.
Doing so you can loop until the new thread which is creating the xml files
has completed and then read the files only after it has completed.

It would look something like this:

Dim NewThread As Threading.Thread = New Threading.Thread(AddressOf
CreateXMLFiles)

NewThread.SetApartmentState(Threading.ApartmentState.STA)

NewThread.Start()

While NewThread.IsAlive

'---Here you can continue other processing while you wait for the thread to
finish or just wait.

End While

'---It is now safe to read xml files.

And here is a multi-threading tutorial:
http://www.startvbdotnet.com/threading/default.aspx


Sincerely,

--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top