我已经创建了一个VS应用程序,我已经在另一台计算机上安装了一个副本,我希望通过局域网将它们链接起来,这样如果settings
被放入其中,其他设置也将被保存。
例如,此设置
我在sttings are中创建了一个新的name
,并将其命名为"AdminIn“,将其类型设置为integer
,将其scope
设置为user
,并将其值设置为0
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连接并完成此操作?
发布于 2013-07-18 02:51:06
我发现这个链接提供了一些示例代码,用于修改My.Settings
中可能有用的应用程序范围的变量。我已经用一个简单的表单进行了测试,该表单带有一个计时器和一个标签,显示了AdminIn
设置的当前值,它似乎可以工作。计时器通过检查重新加载的My.Settings
值来更新表单的每个实例上的标签。该变量需要是应用程序范围的,以便可运行该可执行文件的任何计算机上的所有用户都可以访问。
http://www.codeproject.com/Articles/19211/Changing-application-scoped-settings-at-run-time
下面是我用来保持当前管理员数量最新的表单代码。非常简单,但它似乎很好地完成了这项工作。
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
我发现了这种方法的一些东西,它们与其他人已经在他们的评论中提到的内容相关:
My.Settings
.AdminIn
值。CodeProject示例没有任何异常处理,但您可以通过递归调用Sub.,轻松地将此功能用于异常处理
否则,这似乎是一个完全可行的方法来实现你正在谈论的东西。
https://stackoverflow.com/questions/17704010
复制相似问题