多个通知图标使用多线程的时候出现 [英] Multiple notification icons appear when using multithreading

查看:126
本文介绍了多个通知图标使用多线程的时候出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景: 我正与一个相对简单的WinForms应用程序,写在VB.NET在.NET 3.5框架的Visual Studio 2010。

Context: I'm working with a relatively simple winforms application, written in VB.NET on the .NET 3.5 framework in Visual Studio 2010.

问题: 该程序打开时FormLoad事件创建两个线程。一种处理自动更新检查和其他执行耗时与互联网任务同步文件。这些主题被初始化如下:

Issue: The FormLoad event creates two threads when the program is opened. One handles automatic update checking and the other performs a time consuming task syncing files with the internet. These threads are initialized as follows:

   Dim update_check_thread As New Threading.Thread(AddressOf auto_update_check)
   update_check_thread.IsBackground = True
   update_check_thread.Start()

该表格还使用NotifyIcon控件来绘制任务栏上的通知图标。不幸的是,每个线程启动会导致应用程序绘制一个额外的图标到任务栏。额外的图标绘制(有时)当任何螺纹函数用于该程序打开之后

The form also uses the NotifyIcon control to draw a notification icon on the taskbar. Unfortunately, each thread started causes the application to draw an additional icon to the taskbar. Additional icons are drawn (sometimes) when any threaded function is used after the program is opened.

有没有一种方法来节流的图标数的形式允许吸取?我试着动了code到后台工作,但同样的事情不断发生。

Is there a way to "throttle" the number of icons that the form is allowed to draw? I've tried moving the code to a background worker, however the same thing continues to happen.

在此先感谢!

推荐答案

这是一个常见的​​问题有在VB.NET。它支持可怕使用类名作为对象的语法,就像Form1.Show()。这往往会导致麻烦,当你使用线程,引用这样的类名创建一个新实例的Form1类的上线使用时。另一种形式,它是不可见的,因为它的Show()方法永远不会被调用。但是你看到额外的NotifyIcon。你必须要解决这个问题,它会导致其他的麻烦,以及因为无论你以为你做了可见的形式实际发生的无形之一。

This is a common kind of problem to have in VB.NET. It supports the horrid 'use the class name as an object' syntax, like Form1.Show(). This invariably causes trouble when you use threads, referencing the class name like that creates a new instance of the Form1 class when used on a thread. Another form, it isn't visible because its Show() method was never called. But you do see the extra NotifyIcon. You'll have to fix this, it causes other trouble as well because whatever you thought you'd do to the visible form actually happens on the invisible one.

添加子新的类,并设置一个断点就可以找到code,这是否。

Add Sub New to the class and set a breakpoint on it to find the code that does this.

这篇关于多个通知图标使用多线程的时候出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆