472,805 Members | 1,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 4131

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 !=...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.