IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Framework .NET Discussion :

Service : Win32 error sur récupération d'un System.Windows.Threading.Dispatcher


Sujet :

Framework .NET

  1. #1
    Membre émérite
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2006
    Messages
    1 627
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 627
    Points : 2 331
    Points
    2 331
    Par défaut Service : Win32 error sur récupération d'un System.Windows.Threading.Dispatcher
    Bonjour,

    j'ai un service .net qui peut héberger des drivers, chaque driver étant chargé à la manière d'un plugin.

    Chaque interaction est géré par un thread de messagerie taggé comme STA et background, qui appelle les méthodes qui vont bien sur le driver.

    Je rencontre un souci avec un des drivers. Le driver a besoin d'un context graphique (ActiveX en dessous...), géré par la classe BackStaDispatcher dont la construction est :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
     
            private static BackStaDispatcher _BackStaDispatcher = null;
            private static System.Windows.Threading.Dispatcher _dispatcher;
            private System.Threading.Thread _thread = null;
            private static int _Cpt = 0;
            private System.Windows.Window _Window = null;
            private System.Threading.AutoResetEvent are = null;
     
     
            public static BackStaDispatcher GetInstance()
            {
                if (_BackStaDispatcher == null)
                    _BackStaDispatcher = new BackStaDispatcher("Another Sta dispatcher");
                return _BackStaDispatcher;
            }
     
            private BackStaDispatcher(string name)
            {
                Console.WriteLine("BackStaDispatcher.ctor");
     
                are = new System.Threading.AutoResetEvent(false);
                _thread = new System.Threading.Thread((System.Threading.ThreadStart)delegate
                {
     
                    // Create our context, and install it:
                    System.Threading.SynchronizationContext.SetSynchronizationContext(
                        new System.Windows.Threading.DispatcherSynchronizationContext(
                            System.Windows.Threading.Dispatcher.CurrentDispatcher));
     
                    _dispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher;
                    _Window = new System.Windows.Window();
                    // When the window closes, shut down the dispatcher
                    _Window.Closed += (s, e) =>
                       System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvokeShutdown(System.Windows.Threading.DispatcherPriority.Background);
                    _Window.Loaded += new System.Windows.RoutedEventHandler(_Window_Loaded);
                    _Window.Show();
     
                    _Cpt++;
                    System.Windows.Threading.Dispatcher.Run();
                    _Cpt--;
                    Console.WriteLine("BackStaDispatcher FIN Dispatcher RUN _Cpt=" + _Cpt);
                });
                _thread.Name = string.Format("BackStaDispatcher({0})", name);
                _thread.SetApartmentState(System.Threading.ApartmentState.STA);
                _thread.IsBackground = true;
                _thread.Start();
                are.WaitOne();
            }
     
    ... Invoke, BeginInvoke et autres joyeusetés....
    L'appel au get sur System.Windows.Threading.Dispatcher.CurrentDispatcher; m'envoie sur les roses, si je démarre mon logiciel en tant que service Windows. Si je le lance en mode console, c'est cool (and wo, WTF ?).

    Symptômes : le process crash sur une erreur Win32, loggée dans le journal d'événements comme suit :

    The process was terminated due to an unhandled exception.

    Exception Info: System.ComponentModel.Win32Exception

    Stack:
    at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D)
    at MS.Win32.HwndWrapper..ctor(Int32, Int32, Int32, Int32, Int32, Int32, Int32, System.String, IntPtr, MS.Win32.HwndWrapperHook[])
    at System.Windows.Threading.Dispatcher..ctor()
    at System.Windows.Threading.Dispatcher.get_CurrentDispatcher()
    at Driver.BackStaDispatcher.<.ctor>b__0()
    at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
    J'en perds mon latin, si un pro des routines internes windowsienne pouvait venir à mon secours, je lui en serai reconnaissant.

  2. #2
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Points : 39 749
    Points
    39 749
    Par défaut
    J'ai pas tout compris à ton histoire, mais pourquoi tu utilises un Dispatcher (qui est un composant WPF, donc lié à l'UI) pour un service Windows, qui par définition n'a pas d'UI ?

  3. #3
    Membre émérite
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2006
    Messages
    1 627
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 627
    Points : 2 331
    Points
    2 331
    Par défaut
    La question qui tue ^^

    Le driver repose en dessous sur un activeX, qui existe normalement dans un contexte graphique...

  4. #4
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Points : 39 749
    Points
    39 749
    Par défaut
    Citation Envoyé par Arnard Voir le message
    Le driver repose en dessous sur un activeX, qui existe normalement dans un contexte graphique...
    Bah oui mais pour un service, il n'y a pas de contexte graphique... Tu es sûr qu'il ne suffit pas d'être dans un thread STA ?

  5. #5
    Membre émérite
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2006
    Messages
    1 627
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 627
    Points : 2 331
    Points
    2 331
    Par défaut
    Pour fonctionner (cet %µ£ d'activeX), il lui faut un écosystème graphique, car sinon il ne remonte pas les événements que l'on attend de lui, et comme j'host le tout (en mode STA ^^), je suis lié à la problématique

    J'ai cablé d'autres activeX sans souci, STA suffisait. Juste que pour celui-là, disons que la problématique Service n'a pas été anticipée.

    De toute manière c'était la problématique à 1 million d'entrée de jeu, j'étais surtout curieux de savoir si j'avais pu louper un élément contextuel dans l'exécution du process, ou si l'erreur pouvait parler à quelqu'un (dans le genre "ah mais oui il te faut positionner le flag ZbY28 à la valeur quarante-douze"...)

Discussions similaires

  1. [techno] Developper sur un site un systeme de RSS
    Par nicordi dans le forum Général Conception Web
    Réponses: 3
    Dernier message: 20/10/2005, 01h38
  2. [Access] Ne pas montrer #Error sur un rapport Access
    Par nico33307 dans le forum Access
    Réponses: 3
    Dernier message: 23/09/2005, 00h19
  3. [C#] Récupération des variables system...
    Par smyley dans le forum Windows Forms
    Réponses: 7
    Dernier message: 04/08/2005, 12h39
  4. [web services axis ] deployment sur axis
    Par warax dans le forum Services Web
    Réponses: 7
    Dernier message: 17/05/2005, 15h44
  5. Question sur l'instruction [b] system[/b]
    Par Sniper37 dans le forum MFC
    Réponses: 8
    Dernier message: 03/03/2004, 17h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo