Threads and synchronization with Merge Replication

L

Lonifasiko

Hi,

When starting my application for the first time, I must retrieve all
data from server database with Merge Replication. What I do is start a
new thread with runs a splash form separately, only runs the form, not
the code for replication. Application, first time executes replication
code with Synchronize() synchronous method and then closes the splash
form correctly.

Second time and others, replication executes Synchronize() method but
inmediately closes all the application, not only the thread I start
when a replication must be done. Why if Sinchronize() method is
synchronous? I've also tried with asynchronous calls but there is no
way.
I would need something that would close the splash form and would
return control to the main thread of the application. First time, as
replication is slower, this works correctly, but next times, when
synchronization is quicker, does not. This second time, when splash
form thread is closed, it seems that there are no more threads on the
PPC and therefore, application is completely closed. Could be?
This is my code:
 
L

Lonifasiko

Ummmmmmmm, I forgot the code:

//This code is located in the constructor of the parent form of my
application. It is executed every 5 minutes
Thread splashThread = new Thread(new ThreadStart(StartSplash));
splashThread.Start();
Application.DoEvents();

// Check if the database file already exists
if (!System.IO.File.Exists(Constants.DatabaseFilePath))
{
//Add a new subscripton and create the
local database file

replicationManager.AddSubscription(AddOption.CreateDatabase);

// La replicación inicial es
necesariamente síncrona ya que no existe la BD en local
replicationManager.Synchronize();

replicationManager.Dispose();
}
catch()
{
CloseSplash();
}
finally
{
CloseSplash();
}


public void StartSplash()
{
splash = new SplashForm(userId);
Application.Run(splash);
}


private void CloseSplash()
{
if (splash == null)
return;

MessageBox.Show("MATANDO THREAD!");
// Shut down the splash screen
splash.Invoke(new EventHandler(splash.KillMe));
splash.Dispose();
splash = null;
}

Hope you can help me a little bit. Thanks very much.
 

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