Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Strange (sorry that is the best title I could come up wi
Message
De
21/03/2005 10:18:23
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00997385
Message ID:
00997828
Vues:
10
Einar,

It works fine for me with the message box.

~~Bonnie

>I have found what the problem was. The problem was that I didn't post exactly the same code as the code I was trying to run. The code I tried to run had an extra messagebox statement:
>
>System.Management.ManagementObjectCollection UserSearch = new System.Management.ManagementObjectSearcher("Select * FROM Win32_Account").Get();
>			
>MessageBox.Show("Count:"+UserSearch.Count.ToString()); // removing this line will noth throw an exception in the foreach
>
>foreach(System.Management.ManagementObject mo in UserSearch)
>{
>	if (MessageBox.Show(mo["Name"].ToString(),"next?",MessageBoxButtons.YesNo) == DialogResult.No)
>	{
>		break;
>	}	
>}
>
>
>The exception that is thrown in the foreach has the following message:
>
>
>An unhandled exception of type 'System.Management.ManagementException' occurred in system.management.dll
>Additional information: COM object that has been separated from its underlying RCW can not be used.
>
>
>I am unsure why the messagebox causes problems.
>
>Could you guys please try to run the code above whith and without the messagebox before the foreach loop just to verify that I am not seeing things?
>
>Any explanation offered for this would also be appreciated.
>
>Thanks,
>Einar
>
>
>>Here is some strange code. button11_Click throws an exception in the foreach body. They both look like apples to me :)
>>
>>
>>private void button11_Click(object sender, System.EventArgs e)
>>{
>>	ManagementObjectCollection UserSearch = new ManagementObjectSearcher("Select * FROM Win32_Account").Get();
>>	foreach(ManagementObject mo in UserSearch)
>>	{
>>		MessageBox.Show(mo["Name"].ToString());	
>>	}
>>}
>>
>>private void button12_Click(object sender, System.EventArgs e)
>>{
>>	System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_Account");
>>	foreach (System.Management.ManagementObject mo in searcher.Get())
>>	{
>>		MessageBox.Show(mo["Name"].ToString());
>>	}
>>}
>>
>>
>>Is there something I am missing? Why will one work and not the other one?
>>It is not a big deal but it is driving me crazy.
>>
>>Einar
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform