多个STA(单线程公寓)在asp.net Web应用程序中不起作用 [英] Multiple STA (Single Thread Apartment ) is not working in asp.net web application

查看:75
本文介绍了多个STA(单线程公寓)在asp.net Web应用程序中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我创建了一个简单的asp.net Web应用程序。它有两个按钮,一个用于浏览文件夹(selectFolderbtn)&另一个用于浏览文件(selectFilebtn)。两个按钮的点击事件如下: -

Hi all,

I have created a simple asp.net web application. It has two buttons one for browsing folder (selectFolderbtn) & another for browsing file (selectFilebtn) . And the click event for both the buttons are as below:-

protected void selectFolderbtn_Click(object sender, EventArgs e)
 {
     Thread thdSyncRead = new Thread(new ThreadStart(openfolder));
     thdSyncRead.SetApartmentState(ApartmentState.STA);
     thdSyncRead.Start();
 }

 public void openfolder()
 {

     FolderBrowserDialog fbd = new FolderBrowserDialog();
     DialogResult result = fbd.ShowDialog();

     string selectedfolder = fbd.SelectedPath;
     txt_extDestLoc.Text = selectedfolder;
      

 }




protected void selectFilebtn_Click(object sender, EventArgs e)
 {
     Thread thdSyncReadNew = new Thread(new ThreadStart(selectfile));
     thdSyncReadNew.SetApartmentState(ApartmentState.STA);
     thdSyncReadNew.Start();

    
     
 }

public void selectfile()
 {

     OpenFileDialog fileD = new OpenFileDialog(); //create object
     fileD.Filter = "Iso files|*.iso;"; //define filter
     fileD.ShowDialog(); //show dialog
     string globalisopath = fileD.FileName;
 
 }



我面临的问题是上述两个按钮点击事件中,只有一个事件一次有效。不是这两件事。我希望点击事件都能正常工作,应该选择一个文件夹&另一个应该选择一个文件。但它不按我想要的方式工作。



为什么会发生这种情况。请告诉我它的解决方案或任何其他替代方案。



感谢您的帮助。


The issue I am facing is among the above two button click event only one event works at a time & not both the event. I want both the click event to work, one should select a folder & another should select a file. But its not working the way I want.

Why this is happening. Please suggest me its solution or any other alternatives.

Thanks for help.

推荐答案

您缺乏什么是Web应用程序的基本知识!

读取您的代码可以让您知道您正在尝试打开W​​indows的文件/文件夹对话框...



您必须了解Web应用程序是断开连接的应用程序...有一部分在客户端计算机上的浏览器内运行(包含HTML / CSS / JavaScript),并且有一部分在Web内部运行服务器计算机上的服务器(IIS / Apache)。你的代码属于应用程序的服务器端,代码的每一个代码都在服务器上运行,因此它都是错的(它试图在服务器上打开对话框!)...



正如我所说 - 你必须重新开始网络开发的基础......
You are lack basic knowledge of what web application is!
Reading your code one can get the idea that you are trying to open file/folder dialog boxes of Windows...

You have to understand that web applications are disconnected applications...There is a part that run inside the browser on the client machine (contains HTML/CSS/JavaScript) and there is a part that run inside the web server (IIS/Apache) on the server machine. Your code belongs to the server side of the application and every peace of code runs on the server and for that it's all wrong (it try to open dialog boxes on the server!)...

As I told - you have to start again with the very basics of web development...


这篇关于多个STA(单线程公寓)在asp.net Web应用程序中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆