• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

VB.NET RemotingServices.GetLifetimeService方法代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.Runtime.Remoting.RemotingServices.GetLifetimeService方法的典型用法代码示例。如果您正苦于以下问题:VB.NET RemotingServices.GetLifetimeService方法的具体用法?VB.NET RemotingServices.GetLifetimeService怎么用?VB.NET RemotingServices.GetLifetimeService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。



在下文中一共展示了RemotingServices.GetLifetimeService方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1: TimerClient

' 导入命名空间
Imports System.Collections
Imports System.Net.Sockets
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Messaging
Imports System.Runtime.Remoting.Lifetime
Imports System.Security.Permissions
Imports TimerService



Public Class TimerClient
    Inherits MarshalByRefObject
    Implements ISponsor
    
    Public Shared Sub Main() 
        Dim myClient As New TimerClient()
    
    End Sub
    
    <SecurityPermission(SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.Infrastructure)> _
    Public Sub New() 
        ' Registers the HTTP Channel so that this client can receive
        ' events from the remote service.
        Dim serverProv As New BinaryServerFormatterSinkProvider()
        serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full
        Dim clientProv As New BinaryClientFormatterSinkProvider()
        
        Dim props As New Hashtable()
        props("port") = 0
        Dim channel As New HttpChannel(props, clientProv, serverProv)
        ChannelServices.RegisterChannel(channel)
        
        Dim remoteType As New WellKnownClientTypeEntry(GetType(TimerService), "http://localhost:9000/MyService/TimerService.soap")
        RemotingConfiguration.RegisterWellKnownClientType(remoteType)
        
        Dim groupTimer As New TimerService()
        groupTimer.MinutesToTime = 4.0
        
        ' Registers this client as a lease sponsor so that it can
        ' prevent the expiration of the TimerService.
        Dim leaseObject As ILease = CType(RemotingServices.GetLifetimeService(groupTimer), ILease)
        leaseObject.Register(Me)
        
        ' Subscribes to the event so that the client can receive notifications from the server.
        AddHandler groupTimer.TimerExpired, AddressOf OnTimerExpired
        Console.WriteLine("Connected to TimerExpired event")
        
        groupTimer.Start()
        Console.WriteLine("Timer started for {0} minutes.", groupTimer.MinutesToTime)
        Console.WriteLine("Press enter to end the client process.")
        Console.ReadLine()
    
    End Sub
    
    
    Private Sub OnTimerExpired(ByVal [source] As Object, ByVal e As TimerServiceEventArgs) 
        Console.WriteLine("TimerHelper.OnTimerExpired: {0}", e.Message)
    
    End Sub
    
    <SecurityPermission(SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.Infrastructure)> _
    Public Function Renewal(ByVal lease As ILease) As TimeSpan Implements ISponsor.Renewal
        Console.WriteLine("TimerClient: Renewal called.")
        Return TimeSpan.FromMinutes(0.5)
    
    End Function 'Renewal
End Class
开发者ID:VB.NET开发者,项目名称:System.Runtime.Remoting,代码行数:70,代码来源:RemotingServices.GetLifetimeService


示例2: Main

' 导入命名空间
Imports System.Collections
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Lifetime
Imports System.Timers



Public Class TimerServer
    
    Public Shared Sub Main() 
        
        Dim serverProv As New BinaryServerFormatterSinkProvider()
        serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full
        Dim clientProv As New BinaryClientFormatterSinkProvider()
        
        Dim props As New Hashtable()
        props("port") = 9000
        Dim channel As New HttpChannel(props, clientProv, serverProv)
        ChannelServices.RegisterChannel(channel)
        RemotingConfiguration.RegisterWellKnownServiceType(GetType(TimerService), "MyService/TimerService.soap", WellKnownObjectMode.Singleton)
        
        Console.WriteLine("Press enter to end the server process.")
        Console.ReadLine()
    
    End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Runtime.Remoting,代码行数:30,代码来源:RemotingServices.GetLifetimeService


示例3: New

' 导入命名空间
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Lifetime
Imports System.Security.Permissions
Imports System.Timers


' Define the event arguments
<Serializable()>  _
Public Class TimerServiceEventArgs
    Inherits EventArgs
    Private m_Message As String
    
    Public Sub New(ByVal message As String) 
        m_Message = message
    
    End Sub
    
    
    Public ReadOnly Property Message() As String 
        Get
            Return m_Message
        End Get
    End Property
End Class


' Define the delegate for the event
Public Delegate Sub TimerExpiredEventHandler(ByVal sender As Object, ByVal e As TimerServiceEventArgs) 

' Define the remote service class

Public Class TimerService
    Inherits MarshalByRefObject
    Private m_MinutesToTime As Double
    Private m_Timer As Timer
    
    ' The client will subscribe and unsubscribe to this event
    Public Event TimerExpired As TimerExpiredEventHandler
    
    
    ' Default: Initialize the TimerService to 4 minutes, the time required
    ' to brew coffee in a French Press.
    Public Sub New() 
        MyClass.New(4.0)
    
    End Sub
    
    
    Public Sub New(ByVal minutes As Double) 
        Console.WriteLine("TimerService instantiated.")
        m_MinutesToTime = minutes
        m_Timer = New Timer()
        AddHandler m_Timer.Elapsed, AddressOf OnElapsed
    
    End Sub
    
    
    Public Property MinutesToTime() As Double 
        Get
            Return m_MinutesToTime
        End Get
        Set
            m_MinutesToTime = value
        End Set
    End Property
    
    
    Public Sub Start() 
        If Not m_Timer.Enabled Then
            Dim interval As TimeSpan = TimeSpan.FromMinutes(m_MinutesToTime)
            m_Timer.Interval = interval.TotalMilliseconds
            m_Timer.Enabled = True
        Else
        End If
     ' TODO: Raise an exception
    End Sub
    
    
    Private Sub OnElapsed(ByVal [source] As Object, ByVal e As ElapsedEventArgs) 
        m_Timer.Enabled = False
        
        ' Fire Event
        If Not (TimerExpiredEvent Is Nothing) Then
            ' Package String in TimerServiceEventArgs
            Dim timerEventArgs As New TimerServiceEventArgs("TimerServiceEventArgs: Timer Expired.")
            Console.WriteLine("Firing TimerExpired Event")
            RaiseEvent TimerExpired(Me, timerEventArgs)
        End If
    
    End Sub
    
    <SecurityPermission(SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.Infrastructure)> _
    Public Overrides Function InitializeLifetimeService() As [Object] 
        Dim lease As ILease = CType(MyBase.InitializeLifetimeService(), ILease)
        If lease.CurrentState = LeaseState.Initial Then
            lease.InitialLeaseTime = TimeSpan.FromMinutes(0.125)
            lease.SponsorshipTimeout = TimeSpan.FromMinutes(2)
            lease.RenewOnCallTime = TimeSpan.FromSeconds(2)
            Console.WriteLine("TimerService: InitializeLifetimeService")
        End If
        Return lease
    
    End Function 'InitializeLifetimeService
End Class
开发者ID:VB.NET开发者,项目名称:System.Runtime.Remoting,代码行数:108,代码来源:RemotingServices.GetLifetimeService



注:本文中的System.Runtime.Remoting.RemotingServices.GetLifetimeService方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET RemotingServices.IsTransparentProxy方法代码示例发布时间:2022-05-26
下一篇:
VB.NET RealProxy.SupportsInterface方法代码示例发布时间:2022-05-26
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap