我的backgroundWorker Dim con As New SqlConnection("Data source=" & My.Settings.ip & "," & My.Settings.port & ";Network Library=DBMSSOCN;initial catalog=offpodb;User id=" & My.Settings.username & ";Password=" & My.Settings.password & ";")
con.Open()
If connected.Dispatcher.CheckAccess Then
connected.Content = "text"
Else
' i dunno what to use here as it is not the same as WinForms
End If
事件有很多代码要执行。是否可以在执行每个代码后更改标签文本?
例如:
Label1.Invoke((MethodInvoker)delegate {
Label1.Text = i.ToString() + "Files Converted";});
怎么办?
或
请帮我把这个c#代码转换成WPF VB.NET
<div class="panel-body">
<div class="col-md-6">
<p>1. Fill Full Name</p>
<p> Example</p>
<label for="name" class="col-sm-2 control-label">Full Name<span class="important">*</span></label>
<div class="col-sm-6">
<input type="text" class="form-control" id="name" name="name" size="40" maxlength="50" disabled="disabled"
value="Full Name" required>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<p>3. Title #3</p>
<p> Content for #3</p>
<label for="name" class="col-sm-2 control-label">Label #3<span class="important">*</span></label>
<div class="col-sm-6">
<input type="text" class="form-control" id="name" name="name" size="40" maxlength="50" disabled="disabled"
value="Label #3" required>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<!-- Phone Ext -->
<div class="panel-body">
<p>2. Fill Phone Extention</p>
<p> Extention</p>
<label for="name" class="col-sm-1 control-label">Phone Extention<span class="important">*</span></label>
<div class="col-sm-3">
<input type="text" class="form-control" id="name" name="name" size="40" maxlength="50" disabled="disabled"
value="Phone Extention" required>
<div class="help-block with-errors"></div>
</div>
</div>
答案 0 :(得分:1)
您不应使用DoWork
方法更新用户界面。
每项任务完成后,在ReportProgress
方法中调用DoWork
。设置要在UserState
参数中显示的消息。
然后处理表单中的ProgressChanged
事件,从e.UserState
中提取邮件并使用它来更新您的标签。
将其视为后台工作人员通过调用ReportProgress
发送邮件,并通过处理ProgressChanged
接收邮件的主表单。