草庐IT

save_current_side

全部标签

c# - 如何访问 Task.Factory.StartNew 中的 HttpContext.Current?

我想在我的asp.net应用程序中访问HttpContext.CurrentTask.Factory.Start(()=>{//HttpContext.Currentisnullhere});我该如何修复这个错误? 最佳答案 Task.Factory.Start将启动一个新的Thread并且因为HttpContext.Context是线程的本地它不会会被自动复制到新的Thread,所以需要手动传递:vartask=Task.Factory.StartNew(state=>{varcontext=(HttpContext)state;

C# Settings.Default.Save() 不保存?

这个问题在这里已经有了答案:Whyaremyapplicationsettingsnotgettingpersisted?(4个答案)关闭5年前。这个错误很不寻常。基本上我的代码将更改Settings.Default.Example然后保存并重新启动程序。然后当它加载时,它会显示一个消息框。然而奇怪的是,当表单加载时它显示一个空值。这是我的代码:Main.csprivatevoidButton1_Click(objectsender,EventArgse){Settings.Default.Example="Somevalue";//SetsavaluetothesettingsSet

c# - 静态方法中的 HttpContext.Current.Response

我在静态类中有以下静态方法。我的问题是在静态方法中使用HttpContext.Current.Response安全吗?我想100%确定它是线程安全的并且只与调用线程关联。有人知道答案吗?publicstaticvoidSetCookie(stringcookieName,stringcookieVal,System.TimeSpants){try{HttpCookiecookie=newHttpCookie(CookiePrefix+cookieName){Value=cookieVal,Expires=DateTime.Now.Add(ts)};HttpContext.Current

c# - WPF 选项卡控件 : How do I get the currently selected tab?

在我的选项卡SelectionChanged事件中(这是正确的事件,我找不到选项卡更改事件吗?),如何访问新选项卡?同样在正常代码中从这个事件之外,我如何访问当前选择的选项卡?TabControl.SelectionChanged+=newSystem.Windows.Controls.SelectionChangedEventHandler(TabControl_SelectionChanged);voidTabControl_SelectionChanged(objectsender,System.Windows.Controls.SelectionChangedEventArgs

c# - 从 Where(l => l.Side == 'A' ) 与 Where(l => l.Side.Equals ('A' ) 产生的不同 SQL

我一直在LinqPad中试验查询。我们有一个表Lot,其中有一列Sidechar(1)。当我编写linqtosql查询Lots.Where(l=>l.Side=='A')时,它会生成以下SQL--RegionParametersDECLARE@p0Int=65--EndRegionSELECT...,[t0].[Side],...FROM[Lot]AS[t0]WHEREUNICODE([t0].[Side])=@p0但是,使用Lots.Where(l=>l.Side.Equals('A')),它产生--RegionParametersDECLARE@p0Char(1)='A'--End

c# - HttpContext.Current 在异步回调中为 null

尝试在方法回调中访问HttpContext.Current以便修改Session变量,但是我收到异常HttpContext.Current为null。当_anAgent对象触发回调方法时,它会异步触发。在查看similar后,我仍然不确定此问题的解决方案questions在SO上。我的代码的简化版本如下所示:publicpartialclassIndex:System.Web.UI.PageprotectedvoidPage_Load(){//aCallbackisanAction,triggeredwhenacallbackisreceived_anAgent=newWorkAgen

c# - SynchronizationContext.Current 在主 UI 线程的 Continuation 中为 null

我一直在尝试追踪Winforms应用程序中的以下问题:SynchronizationContext.Current在主线程上运行的任务延续(即.ContinueWith)中为null(我希望当前同步上下文为System.Windows.Forms.WindowsFormsSynchronizationContext)。这是演示该问题的Winforms代码:usingSystem;usingSystem.Threading;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceWindowsFormsApplicat

c# - 从单元测试调用时,Application.Current 为空

我有一个方法要从单元测试中调用。此方法在现实生活中将从后台线程运行。它使用一些代码启动对UI线程的调用更新(使用Application.Current.Dispatcher.BeginInvoke....)。然而,当从单元测试中调用时,Application.Current为null。我真的不知道要用if(Application.Current!=null)来解决所有问题。还有其他解决办法吗?_statusUpdates是一个ObservableCollection下面是我要测试的方法中的代码部分(公平地说,它更像是集成测试而不是单元测试)。Application.Current.Di

c# - 异步操作后的 HttpContext.Current.Items

考虑以下ASP.NETWebAPI委托(delegate)处理程序:publicclassMyHandler:DelegatingHandler{protectedasyncoverrideTaskSendAsync(HttpRequestMessagerequest,System.Threading.CancellationTokencancellationToken){varguid=Guid.NewGuid();HttpContext.Current.Items["foo"]=guid;//AnAsyncoperationvarresult=awaitbase.SendAsync

c# - GDI+ 中的 System.Drawing.Image.Save 发生一般性错误

异常:AgenericerroroccurredinGDI+.atSystem.Drawing.Image.Save(Stringfilename,ImageCodecInfoencoder,EncoderParametersencoderParams)atSystem.Drawing.Image.Save(Stringfilename,ImageFormatformat)atSystem.Drawing.Image.Save(Stringfilename)代码:byte[]bitmapData=newbyte[imageText.Length];MemoryStreamstreamB