How to wait for a BackgroundWorker to cancel?

Consider a hypothetical method of an object that does stuff for you: public class DoesStuff { BackgroundWorker _worker = new BackgroundWorker(); ... public void CancelDoingStuff() { _worker.CancelAsync(); //todo: Figure out a way to wait for BackgroundWorker to be cancelled. } } How can one wait for a BackgroundWorker to be done? In the past people have

如何等待BackgroundWorker取消?

考虑一个假设的方法来为你做一些事情: public class DoesStuff { BackgroundWorker _worker = new BackgroundWorker(); ... public void CancelDoingStuff() { _worker.CancelAsync(); //todo: Figure out a way to wait for BackgroundWorker to be cancelled. } } 如何等待BackgroundWorker完成? 过去人们已经尝试过: while (_worker.IsBusy) { Sleep(100); } 但是这种死

Find if process is responding without using System.Diagnostics.Process.Responding

Good day everyone. This problem was part of another one which it as been solved, i realized that what i thought it was the problem after all, it wasn't. Still thanks to that I've learned a couple things. My application does loads of work with IE and from time to time, IE is redirected to a website with some bad Javascript code that ends up blocking IE interface. And consequently blo

查找进程是否正在响应而不使用System.Diagnostics.Process.Responding

今天是个好日子。 这个问题是解决问题的另一个问题的一部分,我意识到我认为这是问题,毕竟它不是。 还要感谢我学到了一些东西。 我的应用程序使用IE浏览器进行大量工作,并且IE会不时重定向到一个网站,这些网站有一些不好的Javascript代码,最终导致IE界面被阻塞。 因此,一旦我的应用程序中的所有内容都在相同的Thread上运行,就会阻止我的应用程 为了解决这个问题,在启动时我的应用程序在另一个Thread中运行一个sta

How can I beautify JSON for display in a TextBox?

How can I beautify JSON with C#? I want to print the result in a TextBox control. Is it possible to use JavaScriptSerializer for this, or should I use JSON.net? Unless I have to, I'd like to avoid deserializing the string. With JSON.Net you can beautify the output with a specific formatting. Demo on dotnetfiddle. Code public class Product { public string Name {get; set;} pu

如何美化JSON以在TextBox中显示?

如何使用C#美化JSON? 我想在TextBox控件中打印结果。 有没有可能为此使用JavaScriptSerializer,还是应该使用JSON.net? 除非必须,否则我想避免对字符串进行反序列化。 使用JSON.Net,您可以使用特定格式美化输出。 在dotnetfiddle上演示。 码 public class Product { public string Name {get; set;} public DateTime Expiry {get; set;} public string[] Sizes {get; set;} } public void Main() {

How to get the current user in ASP.NET MVC

In a forms model, I used to get the current logged-in user by: Page.CurrentUser How do I get the current user inside a controller class in ASP.NET MVC? If you need to get the user from within the controller, use the User property of Controller. If you need it from the view, I would populate what you specifically need in the ViewData , or you could just call User as I think it's a propert

如何在ASP.NET MVC中获取当前用户

在表单模型中,我曾经通过以下方式获取当前登录用户: Page.CurrentUser 如何在ASP.NET MVC中的控制器类中获取当前用户? 如果您需要从控制器中获取用户,请使用Controller的User属性。 如果您从视图中需要它,我会在ViewData填充您特别需要的内容,或者您​​可以调用User,因为我认为它是ViewPage的一个属性。 我发现User工作,即User.Identity.Name或User.IsInRole("Administrator") 。 试试HttpContext.Curre

when Entity Framework is querying a too big data of Varbinary type

I'm trying to query a varbinary column that contain a file (1,2 Gb). I'm using Entity Framework. See below: Database to test CREATE TABLE [dbo].[BIGDATA] ( [id] [bigint] IDENTITY(1,1) NOT NULL, [BIGDATA] [varbinary](max) NULL, CONSTRAINT [PK_BIGDATA] PRIMARY KEY CLUSTERED ([id] ASC) ) ON [PRIMARY] Data to test (any file with 1 Gb) INSERT INTO [dbo].[BIGDATA]([BIGDAT

当实体框架查询Varbinary类型的太大数据时

我试图查询包含文件(1,2 Gb)的varbinary列。 我正在使用实体框架。 见下文: 数据库进行测试 CREATE TABLE [dbo].[BIGDATA] ( [id] [bigint] IDENTITY(1,1) NOT NULL, [BIGDATA] [varbinary](max) NULL, CONSTRAINT [PK_BIGDATA] PRIMARY KEY CLUSTERED ([id] ASC) ) ON [PRIMARY] 要测试的数据(任何带有1 Gb的文件) INSERT INTO [dbo].[BIGDATA]([BIGDATA]) VALUES ((SELECT BulkColumn FROM OPEN

MembershipProvider, IPrincipal, IIdentity?

I have a conceptual question... I am making an Intranet application (Web platform) for a company. I have a SQL Server DB with these tables: Users (userID, userName, userPass, roleID) Roles (roleID, roleName) Pages (pageID, pageURL) RolesXPages(pageID, roleID) How is the best way to create a structure to store all this information while the user navigates the site, I mean, on the thread I shoul

MembershipProvider,IPrincipal,IIdentity?

我有一个概念性问题......我正在为公司制作一个Intranet应用程序(Web平台)。 我有这些表的SQL Server数据库: Users (userID, userName, userPass, roleID) Roles (roleID, roleName) Pages (pageID, pageURL) RolesXPages(pageID, roleID) 在用户浏览网站时创建一个结构来存储所有这些信息的最佳方式是什么,我的意思是说,在这个线程上,我应该能够检查他的角色,他的页面(他可以访问的页面),我一直在阅读在那里我有很

.net Access Forms authentication "timeout" value in code

I'm adding a logout expiration alert to my application and would like to access my web.config forms authentication "timeout" value from my code. Any way i could do this? 我认为你可以从FormsAuthentication静态类方法中读取它,这比直接读取web.config更好,因为你可能从更高级别的web.config继承认证设置。 var authTicket = new FormsAuthenticationTicket(user.EmailAddress, true, (int)FormsAut

.net访问表单身份验证代码中的“超时”值

我正在向我的应用程序添加注销过期警报,并希望从我的代码中访问我的web.config表单身份验证“超时”值。 任何方式,我可以做到这一点? 我认为你可以从FormsAuthentication静态类方法中读取它,这比直接读取web.config更好,因为你可能从更高级别的web.config继承认证设置。 var authTicket = new FormsAuthenticationTicket(user.EmailAddress, true, (int)FormsAuthentication.Timeout.TotalMinutes); 您可以在以下位置访问w

Change default date serialization in WCF

Is there anyway to change the default JSON serialization/deserialization of DateTime in WCF? Currently, DateTime are serialized into the /Date(1372252162657+0200)/ format, which should've been fine but I'm running into issues when my server is not in UTC (which I can't change). All date/time data that is being processed by this service is in UTC format. Everything works when the

更改WCF中的默认日期序列化

无论如何,要改变WCF中默认的JSON序列化/反序列化DateTime? 目前,DateTime被序列化为/Date(1372252162657+0200)/格式,这应该已经很好了,但是当我的服务器不是UTC(我无法更改)时,我遇到了问题。 此服务正在处理的所有日期/时间数据均采用UTC格式。 当服务器使用UTC时,一切正常。 但是,分段/ prod环境设置为GMT + 1(Paris),并且序列化程序假定日期/时间在GMT + 1,完全忽略Kind属性。 所以如你所期望的那样,调

Using JSON.NET to return ActionResult

This question already has an answer here: Json.Net And ActionResult 2 answers I found a similar stackoverflow question: Json.Net And ActionResult The answer there suggested using return Content( converted, "application/json" ); That seems to work on my very simple page. Instead of serializing using JSON.NET and then calling Json() , why not instead override the Json() method in your con

使用JSON.NET返回ActionResult

这个问题在这里已经有了答案: Json.Net和ActionResult 2的答案 我发现了一个类似的stackoverflow问题:Json.Net和ActionResult 那里的答案建议使用 return Content( converted, "application/json" ); 这似乎在我非常简单的页面上工作。 而不是使用JSON.NET进行序列化,然后调用Json() ,而不是重写控制器中的Json()方法(或者可能是基本控制器以增强其可重用性)? 这是从这篇博文中拉出来的。 在您的控制器(或

ASP.NET MVC Core/6: Multiple submit buttons

I need multiple submit buttons to perform different actions in the controller. I saw an elegant solution here: How do you handle multiple submit buttons in ASP.NET MVC Framework? With this solution, action methods can be decorated with a custom attribute. When the routes are processed a method of this custom attribute checks if the attribute's property matches the name of the clicked subm

ASP.NET MVC Core / 6:多个提交按钮

我需要多个提交按钮来在控制器中执行不同的操作。 我在这里看到了一个优雅的解决方案:如何处理ASP.NET MVC框架中的多个提交按钮? 有了这个解决方案,操作方法可以用自定义属性进行修饰。 处理路由时,此自定义属性的方法会检查属性的属性是否与单击的提交按钮的名称相匹配。 但在MVC Core(RC2每晚构建)中,我还没有找到ActionNameSelectorAttribute (我也搜索了Github存储库)。 我找到了一个类似的解决方案,它使用