我正在开发一个显示多个TabItems 的支持工具TabControl.每个TabItem代表一个员工,在这些员工Tab的每个人中都有另一个TabControl包含额外TabItem的员工.这些TabItem代表该员工的Outlook文件夹(如"正在工作","已完成"等).这些文件夹中TabItem的每一个都包含一个ListBox绑定到与该Outlook文件夹相关ObservableCollection的MailItems的文件夹.这些不是巨大的收藏 - 每个只有十几件ListBox.虽然总的来说,所有人都TabItem可以想到100件左右.
我目前构建应用程序的方式是应用程序启动并使用相应的员工选项卡和子选项卡填充屏幕.这个过程相当快,我很高兴.我创建了一个静态Global.System.Timer文件,所有文件夹TabItem的代码隐藏都与之同步.因此,应用程序每5分钟清除一次ObserverableCollection并重新扫描Outlook文件夹.
问题是扫描过程使应用程序停止.我尝试使用a BackgroundWorker从Outlook收集邮件作为后台进程,然后将一个List<MailItem>对象传递给一个RunWorkerCompleted方法,然后运行一个this.Dispatcher.BeginInvoke清除相应的进程,ObservableCollection然后将项目从List<MailItem>后面添加到ObservableCollection.我甚Dispatcher至将此设置为较低优先级.
尽管如此,在扫描/填充ListBox过程中应用程序非常笨重.我不清楚如何更好地设计这个,我承认我对此有些新意.我意识到清除每个ObservableCollections都是低效的,但Outlook文件夹更改事件并不是特别可靠,所以我需要每隔一段时间重新扫描一次以确保所有MailItems都被表示.
下面是我的WPF控件的代码,其中包含ListBox.请记住,这些ListBox控件中大约有10个同时处于活动状态.
// This entire UserControl is essentially a ListBox control
public partial class TicketListView : …Run Code Online (Sandbox Code Playgroud) 我找了很长时间没有成功解决这个问题的方法.
我正在将一些C#代码移植到F#,我正在为一个WPF元素的Dispatcher.Invoke而苦苦挣扎.由于我是F#中的总菜鸟,我唯一能确定的是问题出在椅子和键盘之间.
这是我的C#代码:
foreach (var k in ChartList.Keys)
{
ChartList[k].Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
ChartList[k].Width = area.Width / totalColsForm;
ChartList[k].Height = area.Height / totalRowsForm;
ChartList[k].Left = area.X + ChartList[k].Width * currentCol;
ChartList[k].Top = area.Y + ChartList[k].Height * currentRow;
ChartList[k].doShow();
}
));
}
Run Code Online (Sandbox Code Playgroud)
我正在努力的部分是新的Action(delegate()...).编译器不喜欢我试图翻译它.
F#中这个片段的翻译是什么?
试图制作一些弹簧示例程序 - 不断得到错误 - 发生我的控制器无法处理/你好请求.这是来自log4j的调试信息.
13:50:58,502 {TRACE} DispatcherServlet.initContextHolders:1018 - Bound request context to thread: org.apache.catalina.connector.RequestFacade@636f2067
13:50:58,503 {DEBUG} DispatcherServlet.doService:823 - DispatcherServlet with name 'springtest' processing GET request for [/springtest_2/hello]
13:50:58,504 {TRACE} DispatcherServlet.getHandler:1088 - Testing handler map
[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@7bab2c3] in DispatcherServlet with name 'springtest'
13:50:58,504 {DEBUG} RequestMappingHandlerMapping.getHandlerInternal:220 - Looking
up handler method for path /hello
13:50:58,504 {DEBUG} RequestMappingHandlerMapping.getHandlerInternal:230 - Did not find handler method for [/hello]
13:50:58,504 {TRACE} DispatcherServlet.getHandler:1088 - Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@722e242b] in DispatcherServlet with name 'springtest'
13:50:58,505 {TRACE} BeanNameUrlHandlerMapping.getHandlerInternal:127 - …Run Code Online (Sandbox Code Playgroud) 我试图在Apache中配置Access-Control-Allow-Origin以允许某些域.下面是我的httpd配置
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
Run Code Online (Sandbox Code Playgroud)
但上面的配置没有做任何事情.听说我们需要启用mod_headers才能使它工作.我运行这个httpd -M命令,发现我的Apache中没有头模块.你能不能告诉我如何启用?
我正在开发我公司的一个项目,他们Dispatcher.Invoke()在很多地方使用。如果我使用BeginInvokeInvoke 而不是 Invoke,那么Synchronisation线程之间工作正常,但在 Invoke 的情况下,应用程序会冻结,甚至不进入委托方法的执行。有谁知道为什么会这样?
任何答案将不胜感激。
Invoke项目中使用的示例代码:
Dispatcher.Invoke(DispatcherPriority.Send,
new DelegateMethod(MethodtoExecute));
private delegate void DelegateMethod();
void MethodtoExecute()
{
try
{
}
catch (Exception /*ex*/)
{
}
finally
{
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 junit 测试我的应用程序。
因此,我设置了以下课程:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/META-INF/spring/applicationContext-test.xml" )
@TransactionConfiguration
@Transactional
public class DispatcherServletTest extends AbstractJUnit4SpringContextTests {
private MockHttpServletRequest request;
private MockHttpServletResponse response;
private DispatcherServlet dispatcher;
@Before
public void setUp() throws Exception {
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
MockServletConfig config = new MockServletConfig("myapp");
config.addInitParameter("contextConfigLocation","classpath*:webmvc-config.xml");
dispatcher = new DispatcherServlet();
dispatcher.init(config);
}
//test cases
Run Code Online (Sandbox Code Playgroud)
}
所以问题是,我的调度程序 servlet 似乎无法向我的任何控制器发送任何请求。
我认为配置中有一些东西 - contextConfigurationLocation。看起来他可以找到文件(否则会抛出异常),但不会加载任何配置
记录者说:
org.springframework.web.servlet.PageNotFound - 未找到带有 URI [http://localhost:8080/myapp/abc] 的 HTTP 请求的映射
但我完全不知道出了什么问题......
我将不胜感激任何帮助!
提前致谢
我的问题:我编写了一个需要读取 .doc 和 .odt 的自动化系统,对其执行一些操作并再次将其导出为 pdf。
目前这对我需要的一切都很好,我可以解决所有问题,直到这个问题:
如果用户提供记录了更改(红线)的文档,我需要自动接受所有更改或隐藏它们。
只要 OOo 显示在屏幕上,我就可以用下面的代码解决这个问题。当我隐藏启动它时,我的调用根本不执行任何操作。
所以,这是我目前所做的:
// DO NOT try to cast this to Desktop as com.sun.star.frame.Desktop is NOT a valid class!
// keep it as Object and cast it to XDesktop later (via queryInterface)
Object desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
XMultiServiceFactory xFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(
XMultiServiceFactory.class, xMCF);
// what goes for desktop above is valid for DispatchHelper as well.
Object dispatchHelper = xFactory.createInstance("com.sun.star.frame.DispatchHelper");
// the DispatchHelper is the class that handles the interaction with …Run Code Online (Sandbox Code Playgroud) 这是UserControl我正在使用的.
this.CardHolderName.Content是label在用户控件的UI中.
public partial class PersonCredential : UserControl
{
public PersonCredential()
{
InitializeComponent();
Dispatcher.BeginInvoke( (Action) (() => {
SCLib type = new SCLib();
type.StartMonitoring();
type.CardArrived += (string ATR) => { this.CardHolderName.Content = ATR; };
};
}));
Run Code Online (Sandbox Code Playgroud)
我仍然得到错误," 调用线程无法访问此对象,因为不同的线程拥有它 "即使我正在使用它Dispatcher.BeginInvoke.
Dispatcher使用方式有什么问题吗?}
编辑:我在内容控件中实例化用户控件,代码隐藏是:
public partial class MainWindow : Window
{
PersonCredential personCredential {get;set;}
public MainWindow()
{
InitializeComponent();
var personCredential = new CoffeeShop.PersonCredential();
//create an instance of user control.
this.personCredentials.Content = personCredential;
// assign it to …Run Code Online (Sandbox Code Playgroud) 我们有一个NUnit测试项目,大约有1000个测试.该项目包含主要用于自定义WPF控件的高级组件测试.我们的构建服务器(TeamCity)上的测试过程经常失败:
InvalidOperationException"已释放LocalDataStoreSlot存储"
mscorlib.dll!System.LocalDataStore.GetData(System.LocalDataStoreSlot slot)
mscorlib.dll!System.Threading.Thread.GetData(System.LocalDataStoreSlot slot)
WindowsBase.dll!System.Windows.Interop.ComponentDispatcher.CurrentThreadData.get()...
测试包含[RequiresSTA]属性,Window.Show(),Dispatcher操作等...所以它绝对不是一个常规的单元测试项目.
失败看起来完全是随机的,我们有80%的可能性进行修订,但大部分时间都没有发生.生产代码中的绝对神秘,有时简单的更改 - 如xaml代码中的更改样式 - 触发失败,然后生产代码中的下一个更改修复它.
这种特定的随机故障使得我们的开发团队有时会非常不安,我们的扩展构建系统因此失败而受到严重阻碍.
我们很少用nunit-console.exe在本地运行项目来重现它.
你们有没有见过这样的测试过程失败?任何提示如何解决此问题将受到高度赞赏.
谢谢
有人可以从实际角度解释一下 Kotlin CoroutineExecutorCoroutineDispatcher和Kotlin Coroutine 之间的区别,即在哪些场景下使用一个协程来对抗另一个协程?CoroutineDispatcher
到目前为止,我一直在使用Dispatchers,但是(据我所知)它不能给我一个后台线程。这就是我使用的原因newSingleThreadExecutor()。
但我注意到的是,我的主进程在使用ExecutorCoroutineDispatcher(1)时永远不会结束( CoroutineDispatcher它按预期完成(2))。经过一番调查后,我似乎应该运行方法close()来ExecutorCoroutineDispatcher完成主流程(3)。由于 CoroutineDispatcher您不必这样做,因此它甚至没有方法close()(4)。是CoroutineDispatcher自动关闭的吗?为什么我们有 for 的关闭流程 ExecutorCoroutineDispatcher,但没有 for CoroutineDispatcher?
下面是我用于测试的代码:
fun main() = runBlocking<Unit> {
val dispatcher1 = Executors.newSingleThreadExecutor().asCoroutineDispatcher() // (1) <-- main process runs indefinitely w/o closing dispatcher1 (3)
val dispatcher2 = Dispatchers.Unconfined // (2)
println("Start")
launch(dispatcher1) {
println("Child")
delay(1000)
printInfo(coroutineContext, this)
}.join()
println("End")
dispatcher1.close() // (3) <-- need to close dispatcher1 for …Run Code Online (Sandbox Code Playgroud)