[英]converting ASP .Net WPF Application to Run Without the Window (Form)
I need to convert my app so it runs by itself, not when the user clicks the submit button on the small form我需要转换我的应用程序以使其自行运行,而不是在用户单击小表单上的提交按钮时
Here's my code:这是我的代码:
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
static readonly HttpClient http = new HttpClient();
public MainWindow()
{
InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
string accountName = "foo";
string userName = "foo1";
string password = "foo2";
string key = "=foo3";
// Query the DB
// SELECT DISTINCT Column FROM View
// List<string> orderNumbers
// foreach(orderNumber in orderNumbers){
// Get the invoice records from the database
List<DBInvoiceModel> invoiceRecords = GetInvoiceRecords(102348);
// Calculate the XML request and send it
string UpdateOrderXML = await UpdateOrder(accountName, password, userName, invoiceRecords);
//string ordersXML = await QueryOrders(key, accountName);
//}
}
Do you have any suggestions?你有什么建议吗? I need to know how to modify the MainWindow so that it will run unattended, in a case where it runs via stored procedure or batch job.
在通过存储过程或批处理作业运行的情况下,我需要知道如何修改 MainWindow 以便在无人值守的情况下运行。
You could move your code out of the Button_Click
event handler into an async
method and call it from both the Click
handler and a Loaded
event handler:您可以将代码从
Button_Click
事件处理程序中移出到async
方法中,并从Click
处理程序和Loaded
事件处理程序中调用它:
public partial class MainWindow : Window
{
static readonly HttpClient http = new HttpClient();
public MainWindow()
{
InitializeComponent();
Loaded += async (e, s) => await UpdateOrder();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
await UpdateOrder();
}
private async Task UpdateOrder()
{
string accountName = "foo";
string userName = "foo1";
string password = "foo2";
string key = "=foo3";
// Query the DB
// SELECT DISTINCT Column FROM View
// List<string> orderNumbers
// foreach(orderNumber in orderNumbers){
// Get the invoice records from the database
List<DBInvoiceModel> invoiceRecords = GetInvoiceRecords(102348);
// Calculate the XML request and send it
string UpdateOrderXML = await UpdateOrder(accountName, password, userName, invoiceRecords);
//string ordersXML = await QueryOrders(key, accountName);
//}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.