Newsgroup: it.comp.lang.visual-basic
Titolo: C# 2008 e Microstation (programma Cad)

So che non dovrei postare qui domande su C# 2008, ma non ho trovato il 
newsgroup adatto.
Con C# 2008 ho creato una form con sopra un pulsante. Il pulsante apre un 
file dgn (cad) ed esegue una scansione (cerca il testo "pippo")
e alla fine appare un MessageBox che riporta il numero contato. Non so 
perchč, ma spesse volte il programma genera un errore ( sotto il 
particolare)
che viene resettato solo riavviando il computer oppure (qualche volta) 
ripetendo l'operazione dopo qualche ora.
Ho l'impressione che, anche se chiudo il file test.dgn prima di cliccare sul 
bottone, Microstation rimanga in esecuzione.
E' possibile una cosa del genere?
Grazie anticipatamente
nero
Sotto il dettaglio dell'errore, ho riportato anche il codice presente sul 
bottone dell form.
Dettaglio errore:
System.Runtime.InteropServices.COMException non č stata gestita
  Message="Non č attivo alcun riferimento del modello"
  Source="MicroStationDGN.Application.1"
  ErrorCode=-
2147221504
  StackTrace:
       in MicroStationDGN.ApplicationClass.get_ActiveModelReference()
       in WindowsFormsApplication1.Form1.button1_Click(Object sender, 
EventArgs e) in C:\Users\Administrator\AppData\Local\Temporary 
Projects\WindowsFormsApplication1\Form1.cs:riga 39
       in System.Windows.Forms.Control.OnClick(EventArgs e)
       in System.Windows.Forms.Button.OnClick(EventArgs e)
       in System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons 
button, Int32 clicks)
       in System.Windows.Forms.Control.WndProc(Message& m)
       in System.Windows.Forms.ButtonBase.WndProc(Message& m)
       in System.Windows.Forms.Button.WndProc(Message& m)
       in 
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& 
m)
       in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, 
Int32 msg, IntPtr wparam, IntPtr lparam)
       in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& 
msg)
       in 
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 
dwComponentID, Int32 reason, Int32 pvLoopData)
       in 
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 
reason, ApplicationContext context)
       in 
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, 
ApplicationContext context)
       in System.Windows.Forms.Application.Run(Form mainForm)
       in WindowsFormsApplication1.Program.Main() in 
C:\Users\Administrator\AppData\Local\Temporary 
Projects\WindowsFormsApplication1\Program.cs:riga 18
       in System.AppDomain._nExecuteAssembly(Assembly assembly, String[] 
args)
       in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence 
assemblySecurity, String[] args)
       in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       in System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       in System.Threading.ExecutionContext.Run(ExecutionContext 
executionContext, ContextCallback callback, Object state)
       in System.Threading.ThreadHelper.ThreadStart()
  InnerException:
---------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MicroStationDGN;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// apre in file presente sotto C:\
String nomeFile = "C:\\test.dgn";
System.Diagnostics.Process.Start(nomeFile);
//create a Microstation object
ApplicationClass ustn = new ApplicationClass();
ElementScanCriteria esc = new ElementScanCriteriaClass();
ElementEnumerator ee;
Int32 counter = 0; // escluda all types
esc.ExcludeAllTypes();
// only scan text element. (Not text node)
esc.IncludeType(MsdElementType.msdElementTypeText);
//scansiona il file attivo
ee = ustn.ActiveModelReference.Scan(esc); // Loop through all elements.
while (ee.MoveNext())
{
if (ee.Current.AsTextElement.Text == "pippo")
counter++;
} // show the result
MessageBox.Show("Ho trovato " + counter + " pippo");
}
}
}
----------------------------------------------------------------------- 

 newsgroup adatto.
microsoft.public.it.dotnet.csharp
Ciao, Vincenzo 

Grazieeeee
ciao