[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

.NET Remoting & the UI Thread in Windows Forms

gavinj

10/29/2004 2:40:00 PM

Hi

I have a windows service which creates a remote object.

As the service is running it updates this remote object with various
strings and intergers.

I then have a windows application which, using a separate thread reads
the status object regularily and then updates the form.

I have read up on Threading in windows forms and am using BeginInvoke
to asynchronously update the UI on the UI thread.

this works fine when i don't read the remote object, but when i do,
after about a minute or so it hangs for a few seconds before reading.
i've tried using ONLY value types (ints + bools) in the status object
but this also hangs.

a code snippet follows at the end of this post, thanks in advance for
any help offered.


WINDOWS APPLICATION
.....

---------------------------------------------------
//get status object
myStatus = (ScannerStatus)Activator.GetObject(typeof(ScannerStatus),"tcp://localhost:8085/myStatus");

//start thread to read it regularily
ThreadStart startDelegate = new ThreadStart(updateStatus);
tStatusUpdater = new Thread(startDelegate);
//tStatusUpdater.Priority = ThreadPriority.Lowest;// .Highest;
tStatusUpdater.IsBackground = true;

tStatusUpdater.Start();


private void updateStatus()
{
for(;;)
{
nTimeTaken ++;
uiUpdateTest(nTimeTaken.ToString());
//this displays a timer on the form, which pauses when a 'hang'
occurs

uiUpdateMessage(myStatus.Test.ToString());
Thread.Sleep(1000);
}
}

delegate void delegateStrParam(string strString);

private void uiUpdateMessage(string strMessage)
{
if(lbCurrentMessage.InvokeRequired)
{
BeginInvoke(new delegateStrParam(uiUpdateMessage), new
object[]{strMessage});
return;
}
lbCurrentMessage.Text = strMessage;
}

private void uiUpdateTest(string strString)
{
if(InvokeRequired)
{
BeginInvoke(new delegateStrParam(uiUpdateTest), new
object[]{strString});
return;
}
lbTimer.Text = strString + " secs";
}


//SINGLETON OBJECT


public class ScannerStatus : MarshalByRefObject
{
public enum eStatus : byte
{
STARTED, STOPPED, QUEUEING, SCANNING, FINISHED, WAITING, READY,
SLEEPING
};

private eStatus myStatus;
private bool bTest = false;

readonly object stateLock = new object();

public bool Test
{
get
{
bTest = !bTest;
return bTest;
}
set
{
bTest=value;
}
}
}