Click here to Skip to main content
15,890,579 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: Lock the USB Pen drive Pin
Henry Minute1-Sep-09 8:51
Henry Minute1-Sep-09 8:51 
AnswerRe: Lock the USB Pen drive Pin
annathor1-Sep-09 20:26
annathor1-Sep-09 20:26 
AnswerRe: Lock the USB Pen drive Pin
Dave Kreskowiak2-Sep-09 4:28
mveDave Kreskowiak2-Sep-09 4:28 
QuestionWindows Service Self Installment Problem Pin
khayyam221-Sep-09 8:04
khayyam221-Sep-09 8:04 
AnswerRe: Windows Service Self Installment Problem Pin
Abhijit Jana1-Sep-09 18:25
professionalAbhijit Jana1-Sep-09 18:25 
GeneralRe: Windows Service Self Installment Problem Pin
khayyam221-Sep-09 20:20
khayyam221-Sep-09 20:20 
GeneralRe: Windows Service Self Installment Problem Pin
khayyam221-Sep-09 21:12
khayyam221-Sep-09 21:12 
QuestionLeasing and sponsoring .net Pin
seconds871-Sep-09 3:32
seconds871-Sep-09 3:32 
Hi,
Nowaday I'm working on .net remoting and I've got some problem with leasing.
there is my code:

//RemoteObject
 public class X : MarshalByRefObject
    {
        public int x;
        public X()
        {
            Console.WriteLine("some X object is done...");
        }
        public void PrintAboutMe()
        {
            ILease itfILease = (ILease)RemotingServices.GetLifetimeService(this);
            Console.WriteLine("CurrentState: " + itfILease.CurrentState);
            Console.WriteLine("InitialLeaseTime: " + itfILease.InitialLeaseTime.Minutes +
                ":" + itfILease.InitialLeaseTime.Seconds);
            Console.WriteLine("CurrentLeaseTime: " + itfILease.CurrentLeaseTime.Minutes +
                ":" + itfILease.CurrentLeaseTime.Seconds);
            Console.WriteLine("RenewOnCallTime: " + itfILease.RenewOnCallTime.Minutes +
                ":" + itfILease.RenewOnCallTime.Seconds);
            Console.WriteLine("SponsorShipTime: " + itfILease.SponsorshipTimeout.Minutes +
                ":" + itfILease.SponsorshipTimeout.Seconds);
            Console.WriteLine("x = " + x);
        }
        public override object InitializeLifetimeService()
        {
            ILease itfLease = (ILease)base.InitializeLifetimeService();
            if (itfLease.CurrentState == LeaseState.Initial)
            {
                itfLease.InitialLeaseTime = TimeSpan.FromSeconds(10);
                itfLease.RenewOnCallTime = TimeSpan.FromSeconds(6);
                itfLease.SponsorshipTimeout = TimeSpan.FromSeconds(6);
            }
           // return null;
            return itfLease;
        }
        public void IncrementX()
        {
            x++;
            Console.WriteLine("\nIncrement x member ...\n");
        }
        public void ChangeLifetime()
        {
            ILease itfILease = (ILease)RemotingServices.GetLifetimeService(this);
            itfILease.Renew(TimeSpan.FromSeconds(20));
        }
    }
//SponsorObjectCode
    public class MySponsor : MarshalByRefObject, ISponsor
    {
        public TimeSpan Renewal(ILease il)
        {
            Console.WriteLine("I've been asked to renew the lease.");          
            return TimeSpan.FromSeconds(20);
        }
    }

//ClientCode:
 public static void Main(string[] args)
        {
            HttpChannel c = new HttpChannel(null,
                new BinaryClientFormatterSinkProvider(),
                null);
            ChannelServices.RegisterChannel(c);

            RemotingConfiguration.RegisterActivatedClientType(
                typeof(X), "http://localhost:667");

            X x = new X();
            Console.WriteLine("Client runs...");      

            x.x = 8;
            x.PrintAboutMe();

            ILease serverLease = (ILease)RemotingServices.GetLifetimeService(x);
            MySponsor sponsor = new MySponsor();
            serverLease.Register(sponsor);

            x.IncrementX();
            Thread.Sleep(8000);
            x.ChangeLifetime();
            x.PrintAboutMe();
           
            Console.ReadKey();
        }

//ServerCode:
static void Main(string[] args)
        {
            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            IDictionary props = new Hashtable();
            props["port"] = 667;

            HttpChannel c = new HttpChannel(props,
                null,
                serverProv);
           
            ChannelServices.RegisterChannel(c );
                RemotingConfiguration.RegisterActivatedServiceType(
                 typeof(X));

            Console.WriteLine("Server runs...");           
            Console.ReadKey();
        }

My first question is:
Whay I can't change CurrentLeaseTime via any way? I think when I increment x member it should change my remote object lease time. I receive the same result when I'm trying to change it by ChangeLifetime() method and even my Sponsor doesn't seem to work.
My second question:
Is any way to catch client remote object on server side? I mean I want to have got a references to client objects.

Thank You in advance!
AnswerRe: Leasing and sponsoring .net Pin
Jack Vanderhorst1-Sep-09 16:15
Jack Vanderhorst1-Sep-09 16:15 
GeneralRe: Leasing and sponsoring .net Pin
seconds872-Sep-09 4:09
seconds872-Sep-09 4:09 
GeneralRe: Leasing and sponsoring .net Pin
Jack Vanderhorst2-Sep-09 13:06
Jack Vanderhorst2-Sep-09 13:06 
QuestionWindows workflow foundation related query Pin
ManishaCTS31-Aug-09 23:55
ManishaCTS31-Aug-09 23:55 
Questionsuite integration toolkit error Pin
varun_mca_ju31-Aug-09 21:12
varun_mca_ju31-Aug-09 21:12 
QuestionDotfuscator Renaming Problem Pin
Arun Jacob31-Aug-09 19:32
Arun Jacob31-Aug-09 19:32 
AnswerRe: Dotfuscator Renaming Problem[Solved] Pin
Arun Jacob31-Aug-09 20:55
Arun Jacob31-Aug-09 20:55 
QuestionReflect to a DLL from a service. Pin
CoderMan201431-Aug-09 17:38
CoderMan201431-Aug-09 17:38 
QuestionTry and Crack this? Pin
govendernathan31-Aug-09 3:21
govendernathan31-Aug-09 3:21 
AnswerRe: Try and Crack this? Pin
Dave Kreskowiak31-Aug-09 4:37
mveDave Kreskowiak31-Aug-09 4:37 
GeneralRe: Try and Crack this? Pin
govendernathan31-Aug-09 20:15
govendernathan31-Aug-09 20:15 
GeneralRe: Try and Crack this? Pin
Pete O'Hanlon31-Aug-09 22:56
mvePete O'Hanlon31-Aug-09 22:56 
QuestionWebservices? System.NullReferenceException Pin
SevM31-Aug-09 1:33
SevM31-Aug-09 1:33 
Questionproblem with gsm modem sim300 Pin
hamedkapak30-Aug-09 14:01
hamedkapak30-Aug-09 14:01 
AnswerRe: problem with gsm modem sim300 Pin
Luc Pattyn30-Aug-09 14:04
sitebuilderLuc Pattyn30-Aug-09 14:04 
Questionremote desktop viewer Pin
sonam200929-Aug-09 23:53
sonam200929-Aug-09 23:53 
AnswerRe: remote desktop viewer Pin
Richard MacCutchan30-Aug-09 10:02
mveRichard MacCutchan30-Aug-09 10:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.