473,395 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Application.Run(<ApplicationContext>) Error 'Item has already been added. Key in dictionary: "- 1" key being added: "- 1"'

Hello!

I have a Application, this throws after some time following exception:

Item has already been added. Key in dictionary: "- 1" key being added: "- 1"

I use Application.Run with ApplicationContext.

This error message comes from deeper levels must be thrown (mscorlib.dll?!)
?.

I saw a similar problem. (see
http://www.dotnet4all.com/Dot-Net-Bo...-doevents.html)

For references, Tipps and solutions I would be grateful.

Bye
Ralf Gedrat

Here is a simple example of Code:
---------------------------------

***START CODE***

'
Public Class ClassMyApplication
'
Inherits System.Windows.Forms.ApplicationContext
'
Private WithEvents PrivateForm1 As New Form
Private WithEvents PrivateForm2 As New Form
Private WithEvents PrivateForm3 As New Form
Private WithEvents PrivateFormN As New Form
'
Public Sub New()
'
Call PrivateForm1.Show()
Call PrivateForm2.Show()
Call PrivateForm3.Show()
Call PrivateFormN.Show()
PrivateForm1.Location = New Point(0, 0)
PrivateForm2.Location = New Point(32, 32)
PrivateForm3.Location = New Point(64, 64)
PrivateFormN.Location = New Point(96, 96)
'
End Sub
Private Sub PrivateFormX_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles PrivateForm1.Closing,
PrivateForm2.Closing, PrivateForm3.Closing, PrivateFormN.Closing
'
Call PublicClassMyApplication.ExitThread()
'
End Sub
Private Sub TuWasMitDerForm(ByVal sender As Object, ByVal e As
System.EventArgs) Handles PrivateForm1.Click, PrivateForm2.Click,
PrivateForm3.Click, PrivateFormN.Click
'
CType(sender, Form).Text = Now
'
End Sub
'
End Class
Module ModuleMyApplication
'
Public PublicClassMyApplication As ClassMyApplication
'
<STAThread()> Public Sub Main()
'
Dim ClApplicationLoaded As Boolean
Try
PublicClassMyApplication = New ClassMyApplication
Call Application.Run(PublicClassMyApplication)
Catch ex As Exception
Call MsgBox(ex.Message)
End Try
'
End Sub
'
End Module

***END CODE***

Here is a listing from
http://www.dotnet4all.com/Dot-Net-Bo...-doevents.html
----------------------------------------------------------------------------
---------------------------------

Found the following interesting discussion in the Newsgroups:

Error after a few hours of DoEvents
by:Jeff Cooper
Hi,

I have an app that often has no windows and uses a NotifyIcon. My Sub
Main
has a loop:
Do Until gExit

Application.DoEvents()

Loop

When running the app in development, it works fine. But when running
the
exe, DoEvents() raises the following error after several hours:

An unhandled exception of type 'System.ArgumentException' occurred in
mscorlib.dll
Additional information: Item has already been added. Key in
dictionary:
"-1" Key being added: "-1"

There's nothing in my app that should happen without human interaction
(clicking, double-clicking the notifyicon, etc). So I'm not sure
what's
happening here. The program is basically just sitting there, waiting
for
something to happen. I left it running last night and found the error
this
morning, so it's not like I'm accidentaly clicking a window or icon
and
raising something. I can't find anything in various groups relating to
this. Anyone have any thoughts?

Thanks,

Jeff

Reply:
by:Armin Zingler

Replace the whole loop by

Application.run

Otherwise you get 100% CPU usage. Instead of setting gExit, call
application.ExitThread. If this doesn't fix the problem, find out the
error
line and post it here.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Reply:
by:James Uren
I'm having the same problem - my loop's almost identical - help us
please!

James

Nov 21 '05 #1
0 4180

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kaveri | last post by:
Hi, I'm working with Data Sets and testing my application with multiple browser Instances. In the Application I'm merging diff datasets into a consolidated one and then displaying. This works...
2
by: MaxiWheat | last post by:
Hi, I am using a software that uses MS Word to create PDF files. When I try to run the sample code (ASP 3.0), I get an error on this statement : Set oWord =...
5
by: Ken Cox [Microsoft MVP] | last post by:
MS has posted this here: http://www.asp.net/faq/ms03-32-issue.aspx Fix for: 'Server Application Unavailable' Error after Applying Security Update for IE...
5
by: Kim Nørby Andersen | last post by:
Hello there I am lost. i receive the output in the bottom, from a site that runs excellently on our development server, but dies on the customer. We have had a first version running at the...
2
by: Tee | last post by:
what's the differences between "Overrides Sub OnError" and "Sub Page_Error" ?
1
by: alan | last post by:
I've try to deploy my application by using Setup Wizard. But after I build the setup application, it got a error said "unrecoverable error!". I don't know what's the problem. In order to the what...
7
by: Tom | last post by:
I have built a VS 2005 C++ application (ported from VC++ 2003). It's a WinForm app. It runs OK on the development system, but when I try to deploy it on any other system, all users gets an error...
20
by: Wes Groleau | last post by:
I was doing update statements in SQL Server 2000. I have a table with over 16 million rows. It came from several hundred delimited text files, and two of the columns are file ID (int) and Line...
0
by: Cralis | last post by:
Hello! Started a new job as a novice c# developer. My line manager has asked our team to do a test on an application the company has already made. Basically, he wants a small tool that can control...
5
by: GHUM | last post by:
hello, in my application I am using hSem = win32event.CreateSemaphore (None, 1, 1,"stringincludinginterfaceandport") rt=win32event.WaitForSingleObject (hSem, 0) if rt !=...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.