|
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.ComponentModel;
using System.Collections.Specialized;
using System.Collections;
using System.Diagnostics;
using System.Net.Sockets;
using System.Runtime.Remoting.Lifetime;
namespace EventBasedAsync
{
class Server : MarshalByRefObject, IServer, ISponsor
{
#region ISponsor Members
TimeSpan ISponsor.Renewal(ILease lease)
{
return TimeSpan.FromSeconds(5);
}
#endregion
#region IServer Members
public int DoSomething(int n, object userState, IDoSomethingCallbacks callbacks)
{
bool cancelRequested;
for (int i = 0; i < 20; i++)
{
if (callbacks != null)
{
callbacks.ReportProgress(5 * i, userState, out cancelRequested);
if (cancelRequested) return -1;
}
Thread.Sleep(500);
}
if (callbacks != null)
{
callbacks.ReportProgress(100, userState, out cancelRequested);
if (cancelRequested) return -1;
}
return n * n;
}
#endregion
#region MarshalByRefObject Overrides
public override object InitializeLifetimeService()
{
return null;
}
#endregion
#region Private Fields
private ArrayList cancelRequests = new ArrayList();
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I got my B.Sc. in Mathematics and Computer Science from Tel Aviv University in 1997. Since then I have developed software in UNIX, Win32 and .NET. I currently live in Haifa.