|
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting.Lifetime;
namespace RemoteLib
{
/// <summary>
/// Represents shared class for use in the client and the server applications.
/// </summary>
public class RemotableClass:MarshalByRefObject
{
/// <summary>
/// Represents the method that will handle cross thread calls.
/// </summary>
/// <param name="text"></param>
private delegate void UIThreadHandler<T>(T param);
/// <summary>
/// Initializes a new instance of the RemotableClass
/// </summary>
public RemotableClass()
{
}
/// <summary>
/// Obtains a lifetime service object to control the lifetime policy for this
/// instance.
/// </summary>
/// <returns>
/// An object of type System.Runtime.Remoting.Lifetime.ILease used to control
/// the lifetime policy for this instance. This is the current lifetime service
/// object for this instance if one exists; otherwise, a new lifetime service
/// object initialized to the value of the System.Runtime.Remoting.Lifetime.LifetimeServices.LeaseManagerPollTime
/// property.
/// </returns>
public override object InitializeLifetimeService()
{
ILease lease = (ILease)base.InitializeLifetimeService();
if (lease.CurrentState == LeaseState.Initial)
{
lease.InitialLeaseTime = TimeSpan.FromMinutes(10);
}
return lease;
}
/// <summary>
/// Writes specified text to the TextBox Control.
/// </summary>
/// <param name="text"></param>
public void WriteText(string text)
{
if (SharedResourcesHandler.InnerTextBox != null)
{
UIThreadHandler<string> uiThreadHandler = new UIThreadHandler<string>(AsyncWriteText);
if (SharedResourcesHandler.InnerTextBox.InvokeRequired)
SharedResourcesHandler.InnerTextBox.BeginInvoke(uiThreadHandler, text);
else
SharedResourcesHandler.InnerTextBox.Text = text;
}
}
/// <summary>
/// Writes specified text to the TextBox Control in the UI thread.
/// </summary>
/// <param name="text"></param>
private void AsyncWriteText(string text)
{
SharedResourcesHandler.InnerTextBox.Text = text;
}
/// <summary>
/// Changes the MonthCalendar date to specified date.
/// </summary>
/// <param name="text"></param>
public void ChangeDate(DateTime date)
{
if (SharedResourcesHandler.InnerMonthCalendar != null)
{
UIThreadHandler<DateTime> uiThreadHandler = new UIThreadHandler<DateTime>(AsyncChangeDate);
if (SharedResourcesHandler.InnerMonthCalendar.InvokeRequired)
SharedResourcesHandler.InnerMonthCalendar.BeginInvoke(uiThreadHandler, date);
else
SharedResourcesHandler.InnerMonthCalendar.SetDate(date);
}
}
/// <summary>
/// Changes the MonthCalendar date to specified date in the UI thread.
/// </summary>
/// <param name="text"></param>
private void AsyncChangeDate(DateTime date)
{
SharedResourcesHandler.InnerMonthCalendar.SetDate(date);
}
}
}
|
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.