您好我想在我的程序中创建一个更新机制(Windows窗体应用程序)。当他们按下登录时,如果有更新,它就会这样做;程序将首先更新然后让他们登录。
<select>
<#list sbUsers as sbUser>
<option value="${sbUser.login}" <#if userName==sbUser.login>selected</#if>>${sbUser.login}</option>
</#list>
</select>
和按钮代码
if (!new WebClient().DownloadString(
"ftp://username:password@wdasd.bplaced.net/test.txt").Contains("1.0.0.0")) {
}
else
{
if (MessageBox.Show("New Update! Would you like to update?", "Yay!",
MessageBoxButtons.YesNo, MessageBoxIcon.Information) ==
System.Windows.Forms.DialogResult.Yes)
{
Process.Start("ftp://username:password@wdasd.bplaced.net/wdasd.bplaced.net.zip");
}
}
我很确定Process.Start不正确。我会在那里键入什么,以便程序查看FTP服务器进行更新?
请不要ClickOnce,我希望它在点击登录时加载更新。没有安装程序。
答案 0 :(得分:1)
也许类似下面的内容可以帮到你:
public async Task CheckForUpdates() {
using(WebClient wc = new WebClient()) {
string s = await wc.DownloadStringTaskAsync("ftp://username:password@wdasd.bplaced.net/test.txt");
if(!s.Contains("1.0.0.0") {
if (MessageBox.Show("New Update! Would you like to update?", "Yay!",
MessageBoxButtons.YesNo, MessageBoxIcon.Information) ==
System.Windows.Forms.DialogResult.Yes)
{
await wc.DownloadFileTaskAsync(
"ftp://username:password@wdasd.bplaced.net/wdasd.bplaced.net.zip",
@"c:\downloadlocation\tmpupdate.zip"
);
// do stuff with file downloaded
}
}
}
return;
}
您可以从另一个函数(在其声明中标记为async
)内调用此方法,如下所示:
await CheckForUpdates();
例如:
private async void button1_Click( object sender, EventArgs e ) {
await CheckForUpdates();
}
async
/ await
允许无阻塞执行后台代码,同时仍然允许用户界面互动。
使用修订后的button
代码:
private async void button2_Click(object sender, EventArgs e) {
//Hash
var hash = SecurePasswordHasher.Hash("password");
//Verify
var result = SecurePasswordHasher.Verify("password", hash);
if (
txtUsername.Text == "" || txt_Password.Text == "") {
MessageBox.Show("Please provide a Username and Password");
return;
}
try {
//Create SqlConnection
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("Select * from [break].[dbo].[tabl_login] where UserName=@username and Password=@password", con);
cmd.Parameters.AddWithValue("@username", txtUsername.Text);
cmd.Parameters.AddWithValue("@password", txt_Password.Text);
con.Open();
SqlDataAdapter adapt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapt.Fill(ds);
con.Close();
int count = ds.Tables[0].Rows.Count;
//If count is equal to 1, than show frmMain form
if (count == 1) {
MessageBox.Show("Login Successful!");
await CheckForUpdates();
} else {
MessageBox.Show("Login Failed!");
}
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
答案 1 :(得分:0)
如果我理解正确的话。这可能会有所帮助
StartCoroutine(PlayerAction(yourPlayerStat,2));