草庐IT

c# - 南希 (C#) : How do I get my post data?

我正在使用CoronaSDK将数据发布到我的C#服务器:headers["Content-Type"]="application/x-www-form-urlencoded"headers["Accept-Language"]="en-US"localbody="color=red&size=small"localparams={}params.headers=headersparams.body=bodynetwork.request(host.."/UpdateHand","POST",nwListener,params)我在服务器上收到一条消息:Post["/UpdateHand

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# - 在 C# 中将 Task<T> 转换为 Task<object> 而无需 T

我有一个充满扩展方法的静态类,其中每个方法都是异步的并返回一些值——就像这样:publicstaticclassMyContextExtensions{publicstaticasyncTaskSomeFunction(thisDbContextmyContext){booloutput=false;//...doingstuffwithmyContextreturnoutput;}publicstaticasyncTask>SomeOtherFunction(thisDbContextmyContext){Listoutput=newList();//...doingstuffwit

c# - 在 Task.Run 中使用 async/await 在 WinForms 上访问 UI 控件

我在具有一个按钮和一个标签的WinForms应用程序中有以下代码:usingSystem;usingSystem.IO;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceWindowsFormsApplication1{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privateasyncvoidbutton1_Click(objectsender,EventArgse){awaitRun();}privateasyncTas

c# - 如何在 C# 中使用 'do' ByVal

据我了解,C#通过引用将参数传递给方法。在VB.NET中,您可以使用ByVal和ByRef指定它。默认值为ByVal。这是为了与VisualBasic6.0兼容,还是只是随机的?另外,我如何指定在C#中使用什么?我有点喜欢按值传递参数的想法。 最佳答案 C#中的参数默认是按值传递的。没有修饰符来明确这一点,但是如果您添加ref/out参数是通过引用。这里通常的混淆是:按值传递值类型(调用者看不到值类型的更改,但理想情况下值类型无论如何都应该是不可变的)通过引用传递值类型(调用者可以看到值类型的更改,但理想情况下值类型无论如何都应该是

c# "task method"也可以是 "async"方法吗?

我正在尝试掌握新的异步CTP内容,我可能在这里感到困惑......我可以有这个“任务方法”,没有问题:publicstaticTaskLongTaskAAsync(){returnTask.Run(()=>{return("AAA");});}但是如果我需要任务执行另一个任务,我可以将其标记为“async”并使用“await”吗?我试过这个:publicasyncstaticTaskLongTaskAAsync(){awaitTask.Delay(2000);returnTask.Run(()=>{return("AAA");});}但随后莫名其妙地得到了这个编译器错误:因为这是一个异

C# Windows 窗体 : On Close Do [Process]

如何让我的窗体在关闭时执行某些操作。 最佳答案 处理FormClosed事件。为此,转到“属性”窗口中的“事件”选项卡并双击FormClosed事件为其添加处理程序。然后您可以将代码放入生成的MyForm_FormClosed处理程序中。您也可以通过覆盖OnFormClosed方法来做到这一点;为此,请在代码窗口中键入overrideonformcl并从IntelliSense中键入OnFormClosed。如果您希望能够阻止表单关闭,请改为处理FormClosing事件,并将e.Cancel设置为true.

c# - 温莎城堡 : How do I inject all implementations of interface into a ctor?

我编写了一个由多个类实现的接口(interface)。我想编写一个服务类,它将所有已注册的实现注入(inject)到它的构造函数中。我能想到的唯一解决方案是在ctor中调用服务定位器并要求它Resolve()所有实现。理想情况下我想要这样的东西-interfaceIVehicle{voidStart();}classCar:IVehicle{publicvoidStart(){Console.WriteLine("Carstarted.");}}classTruck:IVehicle{publicvoidStart(){Console.WriteLine("Truckstarted."

c# - Task.Factory.StartNew 与异步方法

这可能是一个微不足道的问题,但它可能有助于我的基本理解。以下两个实现之间有什么重要区别吗?Task.Factory.StartNew:publicTaskReadAllTextAsync(stringpath){returnTask.Factory.StartNew(()=>File.ReadAllText(path));}StreamReader上的异步方法:publicasyncTaskReadAllTextAsync(stringpath){using(varstream=File.OpenRead(path))using(varreader=newStreamReader(st

c# - await Task.Factory.StartNew(() => vs Task.Start; await Task;

这两种使用await的形式在功能上有什么区别吗?stringx=awaitTask.Factory.StartNew(()=>GetAnimal("feline"));TaskmyTask=newTask(()=>GetAnimal("feline"));myTask.Start();stringz=awaitmyTask;具体来说,1.中每个操作是按什么顺序调用的?是调用StartNew然后调用await,还是在1.中先调用await? 最佳答案 当您使用async和await编写代码时,您应该尽可能使用Task.Run。Task