小编Joh*_*nny的帖子

用双反斜杠替换单反斜杠

看起来很简单吧?好吧,我不知道.

这是我正在尝试的代码:

input = Regex.Replace(input, "\\", "\\\\\\");
Run Code Online (Sandbox Code Playgroud)

但是,我收到一个错误,

ArgumentException未处理 - 在模式结束时解析"\" - 非法\.

我该怎么做呢?

c# regex string replace backslash

19
推荐指数
3
解决办法
3万
查看次数

子表单关闭时父表单关闭

在我的C#应用​​程序中,我有以下方法在主窗体关闭时调用.

private void FormMain_Closing(object sender, FormClosingEventArgs e)
{ 
        // Show this dialog when the user tries to close the main form
        Form testForm = new FormTest();
        testForm.StartPosition = FormStartPosition.CenterParent;
        testForm.ShowDialog();
}   
Run Code Online (Sandbox Code Playgroud)

这将创建一个对话框窗口,显示主窗体何时关闭.但是,我的问题是当用户关闭时testForm,主表单会立即关闭.我已经尝试过各种各样的变种e.Cancel = true;等等,但仍然无法取消关闭的主要表格.

有任何想法吗?


编辑:看起来我正在使用两个ShowModal()连续的问题.调查问题......


编辑:使用this.DialogResult = DialogResult.None;它似乎解决了我的问题.当从模式对话框打开模态对话框时,它显然是WinForms中的已知问题.

c# forms event-handling

6
推荐指数
1
解决办法
4741
查看次数

如何在不阻止UI的情况下使用WebClient?

有人能指点我一个教程或提供一些示例代码来调用System.Net.WebClient().DownloadString(url)方法而不会在等待结果时冻结UI吗?

我认为这需要用线程来完成?是否有一个简单的实现我可以使用没有太多的开销代码?

谢谢!


实现了DownloadStringAsync,但UI仍然处于冻结状态.有任何想法吗?

    public void remoteFetch()
    {
            WebClient client = new WebClient();

            // Specify that the DownloadStringCallback2 method gets called
            // when the download completes.
            client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(remoteFetchCallback);
            client.DownloadStringAsync(new Uri("http://www.google.com"));
    }

    public void remoteFetchCallback(Object sender, DownloadStringCompletedEventArgs e)
    {
        // If the request was not canceled and did not throw
        // an exception, display the resource.
        if (!e.Cancelled && e.Error == null)
        {
            string result = (string)e.Result;

            MessageBox.Show(result);

        }
    }
Run Code Online (Sandbox Code Playgroud)

c# multithreading webclient downloadstring

5
推荐指数
1
解决办法
2297
查看次数