RAPI.ActiveSync.DisconnectNow does not disconnect ActiveSync

Last post 06-05-2008 12:53 by ctacke. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 06-05-2008 8:35

    • mohunt
    • Top 75 Contributor
    • Joined on 05-12-2008
    • Posts 6

    RAPI.ActiveSync.DisconnectNow does not disconnect ActiveSync

    I'm trying to write an application that disconnects ActiveSync when the computer is locked.  I attempting to use RAPI.ActiveSync.DisconnectNow.  The function returns no errors however; ActiveSync is still connnected.  My code is below. 

    Any assistance would be greatly appreicate.

    Thank you

      Imports System

    Imports Microsoft.Win32

    Imports OpenNETCF.Desktop.Communication

    Public Class frmMain

    Dim oRAPI As RAPI

    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

    oRAPI = Nothing

    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    oRAPI = New RAPI

    oRAPI.ActiveSync.AutoConnect = False

    AddHandler SystemEvents.SessionSwitch, AddressOf SystemEvents_SessionSwitch

    End Sub

    Private Sub SystemEvents_SessionSwitch(ByVal sender As Object, ByVal e As SessionSwitchEventArgs)

    Try

    Select Case e.ReasonCase SessionSwitchReason.SessionUnlock

    ActiveSyncDisconnect()

    txtStatus.AppendText("Unlock" & vbCrLf)

    Case SessionSwitchReason.SessionLock

    ActiveSyncConnect()

    txtStatus.AppendText(
    "Lock" & vbCrLf)

    End Select

    Catch ex As Exception

    txtStatus.AppendText(ex.Message & vbCrLf)

    End Try

    End Sub

    Private Function IsActiveSyncConnected() As Boolean

    Dim bStatus As Boolean = False

    Try

    If oRAPI.DevicePresent Then

    bStatus = True

    Else

    bStatus = False

    End If

    Catch ex As Exception

    txtStatus.AppendText(ex.Message & vbCrLf)

    End Try

    Return bStatus

    End Function

    Private Function ActiveSyncConnect() As Boolean

    Dim bStatus As Boolean = True

    Try

    If Not IsActiveSyncConnected() Then

    oRAPI.ActiveSync.ConnectNow()

    End If

    Catch ex As Exception

    txtStatus.AppendText(ex.Message & vbCrLf)

    bStatus = False

    End Try

    Return bStatus

    End Function

    Private Function ActiveSyncDisconnect() As Boolean

    Dim bStatus As Boolean = True

    Try

    If IsActiveSyncConnected() Then

    If oRAPI.Connected Then

    oRAPI.Disconnect()

    End If

    oRAPI.ActiveSync.DisconnectNow()

    End If

    Catch ex As Exception

    txtStatus.AppendText(ex.Message & vbCrLf)

    bStatus = False

    End Try

    Return bStatus

    End Function

     

    Private Sub butConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butConnect.Click

    ActiveSyncConnect()

    End Sub

    Private Sub butDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butDisconnect.Click

    ActiveSyncDisconnect()

    End Sub

    End Class

  • 06-05-2008 12:53 In reply to

    • ctacke
    • OpenNETCF Staff
    • Top 10 Contributor
    • Joined on 07-27-2007
    • Indiana
    • Posts 1,866

    Re: RAPI.ActiveSync.DisconnectNow does not disconnect ActiveSync

    I seem to recall this as known behavior.  Early versions of ActiveSync supported the method, but some time around 3.6 it stopped working, so calling it has no effect.

Page 1 of 1 (2 items)