首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何通过LAN链接Visual Studio应用程序

如何通过LAN链接Visual Studio应用程序
EN

Stack Overflow用户
提问于 2013-07-17 23:29:43
回答 1查看 1K关注 0票数 0

我已经创建了一个VS应用程序,我已经在另一台计算机上安装了一个副本,我希望通过局域网将它们链接起来,这样如果settings被放入其中,其他设置也将被保存。

例如,此设置

我在sttings are中创建了一个新的name,并将其命名为"AdminIn“,将其类型设置为integer,将其scope设置为user,并将其值设置为0

代码语言:javascript
运行
复制
    Dim AI As New My .MySettings

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    AI.AdminIn = AI.AdminIn + 1
Ai.SAve()

End Sub

现在,AI如何也可以在另一台计算机上的其他应用程序中更新。

如何通过LAN连接并完成此操作?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-18 02:51:06

我发现这个链接提供了一些示例代码,用于修改My.Settings中可能有用的应用程序范围的变量。我已经用一个简单的表单进行了测试,该表单带有一个计时器和一个标签,显示了AdminIn设置的当前值,它似乎可以工作。计时器通过检查重新加载的My.Settings值来更新表单的每个实例上的标签。该变量需要是应用程序范围的,以便可运行该可执行文件的任何计算机上的所有用户都可以访问。

http://www.codeproject.com/Articles/19211/Changing-application-scoped-settings-at-run-time

下面是我用来保持当前管理员数量最新的表单代码。非常简单,但它似乎很好地完成了这项工作。

代码语言:javascript
运行
复制
Public Class Form1

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        'Decrement the AdminIn count when the current instance of the form is closed.
        Me.tmrAdminCheck.Stop()
        ChangeMyAppScopedSetting((My.Settings.AdminIn - 1).ToString)
        'Reload the .exe.config file to synchronize the current AdminIn count.
        My.Settings.Reload()
        My.Settings.Save()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Increment the current AdminIn count when a new instance of the form is loaded
        ChangeMyAppScopedSetting((My.Settings.AdminIn + 1).ToString)
        'Reload the .exe.config file to synchronize the current AdminIn count.
        My.Settings.Reload()
        My.Settings.Save()

        Me.lblAdminsIn.Text = "Current Admins In: " & My.Settings.AdminIn.ToString
        'Start the timer to periodically check the AdminIn count from My.Settings
        Me.tmrAdminCheck.Enabled = True
        Me.tmrAdminCheck.Interval = 100
        Me.tmrAdminCheck.Start()
        Me.Refresh()
        Application.DoEvents()
    End Sub

    Private Sub tmrAdminCheck_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAdminCheck.Tick
        'Reload the .exe.config file to synchronize the current AdminIn count.
        My.Settings.Reload()
        Me.lblAdminsIn.Text = "Current Admins In: " & My.Settings.AdminIn.ToString
        Me.Refresh()
        Application.DoEvents()
    End Sub
End Class

我发现了这种方法的一些东西,它们与其他人已经在他们的评论中提到的内容相关:

  1. 应用程序的.exe.config文件必须位于可访问的位置( CodeProject示例默认位于应用程序的可执行目录)。当然,您可以将设置保存到INI文件或另一个共享目录中的其他配置文件中,并完成类似的操作,但此方法使用My.Settings.
  2. You'll可能希望执行一些额外的检查,以确定是否有两个人试图同时进入。如果发生这种情况,配置文件将仍然处于打开和锁定状态,并且不会保存新的AdminIn值。CodeProject示例没有任何异常处理,但您可以通过递归调用Sub.

,轻松地将此功能用于异常处理

否则,这似乎是一个完全可行的方法来实现你正在谈论的东西。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17704010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档