Laden...

Win XP SP3 Bild laden IOException

Erstellt von caldicot vor 12 Jahren Letzter Beitrag vor 12 Jahren 492 Views
C
caldicot Themenstarter:in
51 Beiträge seit 2010
vor 12 Jahren
Win XP SP3 Bild laden IOException

Hi,

ich habe ein Problem und finde Google keine Lösung.
Ich schreibe ein kleines Programm, dass mit einem SystemFileWatcher ein Verzeichnis überwacht in dem TIF Dateien abgelegt werden. Die Tif Datei soll dann in einem neuen Fenster angezeigt werden.

Dazu habe ich folgende Methoden:


        private PicViewer _picViewer;
        private void FileSystemWatcherOnCreated(object sender, FileSystemEventArgs e)
        {
            string ext = Path.GetExtension(e.FullPath);
            if(ext == null)
                return;
            ext = ext.ToLower();

            if(ext != ".tiff" && ext != ".tif")
                return;

            lock (_lockObject)
            {
                    Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => ShowPicViewer(e.FullPath)));
            }
        }

        private static void ShowPicViewer(string filename)
        {
            _picViewer = new PicViewer();
            _picViewer.ShowFullScreen(filename);
        }

PicViewer ist das neue Fenster.
Hier gibt's die Methode ShowFullScreen.


        public void ShowFullScreen(string filename)
        {
            using (FileStream fs = new FileStream(filename, FileMode.Open))
            {
                imgPicture.Source = BitmapFrame.Create(fs, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
            }

            Show();
            Topmost = true;
            WindowState = WindowState.Maximized;
        }

Es tritt eine IOException auf im Konstruktor des FileStreams.
Hier der StackTrace:


Stapel:
   bei System.IO.__Error.WinIOError(Int32, System.String)
   bei System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean)
   bei System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32, System.IO.FileOptions, System.String, Boolean)
   bei System.IO.FileStream..ctor(System.String, System.IO.FileMode)
   bei FaxViewer.PicViewer.ShowFullScreen(System.String)
   bei FaxViewer.MainWindow.ShowPicViewer(System.String)
   bei FaxViewer.MainWindow+<>c__DisplayClass3.<FileSystemWatcherOnCreated>b__1()
   bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   bei System.Windows.Threading.DispatcherOperation.InvokeImpl()
   bei System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   bei System.Threading.ExecutionContext.runTryCode(System.Object)
   bei System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
   bei System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   bei System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   bei System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   bei System.Windows.Threading.DispatcherOperation.Invoke()
   bei System.Windows.Threading.Dispatcher.ProcessQueue()
   bei System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   bei MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   bei System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   bei MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   bei System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   bei System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   bei System.Windows.Threading.Dispatcher.Run()
   bei System.Windows.Application.RunDispatcher(System.Object)
   bei System.Windows.Application.RunInternal(System.Windows.Window)
   bei System.Windows.Application.Run(System.Windows.Window)
   bei System.Windows.Application.Run()
   bei FaxViewer.App.Main()

Das merkwürdige ist:
Ich entwickle auf einem Win7 PC mit VS2010. Hier tritt das Problem nicht auf.
Auf einem Win XP SP3 Rechner tritt die Exception nach dem 2. Mal auf.
Also das erste Bild wird angezeigt, beim Zweiten tritt die IOException auf.
Auf beiden PCs ist .NET 4.0 Extended installiert. Kompilieren tue ich das Projekt gegen das .NET 4.0 Client Profile Framework.

Ich habe auch schon mit BitmapSource mit CacheOption.OnLoad, BeginInit, EndInit.
Jedesmal das selbe Ergebnis.
Windows 7 hat's jedesmal funktioniert.

Ich hab auch schon gelesen, dass es ein Bug in der Windows Imaging Component ist. Eine Lösung habe ich dazu noch nicht gefunden.

Hat jemand eine Idee wie ich das lösen kann?
Danke
caldi