修改vnc相关部分
This commit is contained in:
commit
982b9a8f28
6 files changed
+41
-21
No files matched your search
+2
-1
@@ -6,12 +6,13 @@
|
||||
xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_.EX"
|
||||
xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties"
|
||||
xmlns:vnc="clr-namespace:VncSharp;assembly=VncSharp"
|
||||
mc:Ignorable="d"
|
||||
mc:Ignorable="d" Loaded="Window_Loaded"
|
||||
Title="VNC" Height="450" Width="800">
|
||||
<Grid Margin="0,0,0,0">
|
||||
<Button x:Name="Save" Content="{x:Static lang:Resources.Cancel}" HorizontalAlignment="Right" Height="35" Margin="450,0,50,10" VerticalAlignment="Bottom" Width="80" Click="Save_Click"/>
|
||||
<ContentControl Margin="0,0,0,60">
|
||||
<vnc:RemoteDesktop x:Name="vnc" />
|
||||
</ContentControl>
|
||||
<TextBlock x:Name="log" VerticalAlignment="Bottom" Text="LINK-------" Margin="0,0,0,10" HorizontalAlignment="Left" Width="600" Height="35" FontSize="24" FontWeight="Bold" FontStyle="Italic" />
|
||||
</Grid>
|
||||
</Window>
|
||||
+24
-17
@@ -23,24 +23,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.EX
|
||||
/// </summary>
|
||||
public partial class VNC : Window
|
||||
{
|
||||
string host = "172.0.0.1"; // 替换为你的 VNC 服务器地址
|
||||
string host = "127.0.0.1"; // 替换为你的 VNC 服务器地址
|
||||
int port = 5901; // 替换为你的 VNC 服务器端口
|
||||
string password = " "; // 替换为你的 VNC 服务器密码
|
||||
|
||||
public VNC()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (!vnc.IsConnected)
|
||||
{
|
||||
vnc.Connect(host, false, true);
|
||||
//System.Windows.MessageBox.Show("VNC 连接成功!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -50,30 +39,48 @@ namespace SunlightCentralizedControlManagement_SCCM_.EX
|
||||
}
|
||||
|
||||
|
||||
private bool PingTest(string ip)
|
||||
private async Task<bool> PingTest(string ip)
|
||||
{
|
||||
bool result = false;
|
||||
Ping pingSender = new Ping();
|
||||
|
||||
try
|
||||
{
|
||||
PingReply reply = pingSender.Send(ip, 120);
|
||||
PingReply reply = await pingSender.SendPingAsync(ip, 6);
|
||||
|
||||
if (reply.Status == IPStatus.Success)
|
||||
{
|
||||
result = true;
|
||||
log.Text = ip + " Connected";
|
||||
}
|
||||
else
|
||||
{
|
||||
log.Text = ip + " Timeout";
|
||||
}
|
||||
|
||||
}
|
||||
catch (PingException e)
|
||||
{
|
||||
result = false;
|
||||
log.Text = ip + " Not Connected";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Parameter(object IP,object PROT,object USER ,object PASSWD)
|
||||
{ host = IP.ToString();port =Convert.ToInt16( PROT); password = PASSWD.ToString(); }
|
||||
|
||||
|
||||
private async Task Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (await PingTest(host))
|
||||
{
|
||||
if (!vnc.IsConnected)
|
||||
{
|
||||
vnc.Connect(host, false, true);
|
||||
//System.Windows.MessageBox.Show("VNC 连接成功!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user