草庐IT

dispatch_main_queue_callback

全部标签

c# - 在我的 ViewModel 中使用 Dispatcher 是错误的吗?

我正在将我玩的一个游戏的聊天解析器转换为wpf,主要是为了更好地处理MVVM和wpf。这是我如何设置项目的简要说明查看:现在它只是一个简单的列表框,其中ItemSource绑定(bind)到我的View模型可观察的聊天集合型号:我有多个可以一次登录的角色,每个角色都有一个聊天类。聊天类启动一个后台工作程序,该工作程序从游戏中获取下一行聊天内容,并使用该行触发名为IncomingChat的事件。publiceventActionIncomingChat;我正在使用后台工作程序在我的backgroundworkersprogresschaged事件中触发一个事件,因为当我使用计时器时,我一

c# - "An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full"

我用C#编写了一个IP多播应用程序。它编译得很好,但在运行时这一行:sock.SetSocketOption(SocketOptionLevel.IP,SocketOptionName.AddMembership,newMulticastOption(IPAddress.Parse("224.100.0.1")));抛出未处理的套接字异常:Anoperationonasocketcouldnotbeperformedbecausethesystemlackedsufficientbufferspaceorbecauseaqueuewasfull我在Google中搜索错误,有人建议删除可

c# - "An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full"

我用C#编写了一个IP多播应用程序。它编译得很好,但在运行时这一行:sock.SetSocketOption(SocketOptionLevel.IP,SocketOptionName.AddMembership,newMulticastOption(IPAddress.Parse("224.100.0.1")));抛出未处理的套接字异常:Anoperationonasocketcouldnotbeperformedbecausethesystemlackedsufficientbufferspaceorbecauseaqueuewasfull我在Google中搜索错误,有人建议删除可

c# - 读取 Main Program.cs 中的 appsettings.json

首先,我的主要目的是为我的应用程序动态设置IP和端口。我正在使用IConfiguration注入(inject)一个json配置文件,就像提到的一些教程一样。但是,我无法检索Program.cs中的配置,因为我的WebHostBuilder将同时使用StartUp和Url。因此在主机建立时,我的配置中没有任何内容。WebProtocolSettingssettings_Web=newWebProtocolSettings();varhost=newWebHostBuilder().UseIISIntegration().UseKestrel().UseContentRoot(Direc

c# - 读取 Main Program.cs 中的 appsettings.json

首先,我的主要目的是为我的应用程序动态设置IP和端口。我正在使用IConfiguration注入(inject)一个json配置文件,就像提到的一些教程一样。但是,我无法检索Program.cs中的配置,因为我的WebHostBuilder将同时使用StartUp和Url。因此在主机建立时,我的配置中没有任何内容。WebProtocolSettingssettings_Web=newWebProtocolSettings();varhost=newWebHostBuilder().UseIISIntegration().UseKestrel().UseContentRoot(Direc

c# 将 Remove(int index) 方法添加到 .NET Queue 类

我想使用.NET框架(3.5)中描述的通用队列类但我需要一个Remove(intindex)方法来从队列中删除项目。我可以使用扩展方法实现此功能吗?有人愿意为我指出正确的方向吗? 最佳答案 你想要的是一个List你总是调用RemoveAt(0)当你想从Queue中获取项目时.其他一切都是一样的,真​​的(调用Add会在Queue的末尾添加一个项目)。 关于c#将Remove(intindex)方法添加到.NETQueue类,我们在StackOverflow上找到一个类似的问题:

c# 将 Remove(int index) 方法添加到 .NET Queue 类

我想使用.NET框架(3.5)中描述的通用队列类但我需要一个Remove(intindex)方法来从队列中删除项目。我可以使用扩展方法实现此功能吗?有人愿意为我指出正确的方向吗? 最佳答案 你想要的是一个List你总是调用RemoveAt(0)当你想从Queue中获取项目时.其他一切都是一样的,真​​的(调用Add会在Queue的末尾添加一个项目)。 关于c#将Remove(intindex)方法添加到.NETQueue类,我们在StackOverflow上找到一个类似的问题:

c# - 错误 : Must create DependencySource on same Thread as the DependencyObject even by using Dispatcher

以下是我的View的一部分,我在其中将一个图像绑定(bind)到我的ViewModel中的一个属性:我的ViewModel是这样的:publicclassMainWindowViewModel:INotifyPropertyChanged{publicBitmapImageImage{get{return_image;}set{_image=value;OnPropertyChanged();}}Action_makeScannerAlwaysOnAction;privateBitmapImage_image;publicMainWindowViewModel(){AddNewPers

c# - 错误 : Must create DependencySource on same Thread as the DependencyObject even by using Dispatcher

以下是我的View的一部分,我在其中将一个图像绑定(bind)到我的ViewModel中的一个属性:我的ViewModel是这样的:publicclassMainWindowViewModel:INotifyPropertyChanged{publicBitmapImageImage{get{return_image;}set{_image=value;OnPropertyChanged();}}Action_makeScannerAlwaysOnAction;privateBitmapImage_image;publicMainWindowViewModel(){AddNewPers

C# WinForms : How to set Main function STAThreadAttribute

在后台线程中调用saveFileDialog.ShowDialog()时出现以下异常:Currentthreadmustbesettosinglethreadapartment(STA)modebeforeOLEcallscanbemade.EnsurethatyourMainfunctionhasSTAThreadAttributemarkedonit.根据this:Tofixtheproblem,insertthestatement:Threading.Thread.CurrentThread.ApartmentState=Threading.ApartmentState.STA;