[Approved] - MP1-4502 - TVServer ChannelState.DoSetChannelStates: An unknown error occured setting channel states

Discussion in 'Submit: code patches (MediaPortal/TV-Server/etc.)' started by SiggiK, May 25, 2014.

  1. SiggiK

    SiggiK Portal Member

    Joined:
    September 26, 2009
    Messages:
    19
    Likes Received:
    6
    Gender:
    Male
    Location:
    Karlsruhe
    Ratings:
    +17 / 0
    Home Country:
    Germany Germany
    Show System Specs
    I have made a fix for https://forum.team-mediaportal.com/...-occured-while-setting-channel-states.124482/ and https://forum.team-mediaportal.com/...-occured-while-setting-channel-states.124083/.



    The exception concourse on Thread abort:
    Code (C):
    1. private void AbortChannelStates()
    2. {
    3.  
    4.       lock (_threadlock)
    5.       {
    6.        if (_setChannelStatesThread != null && _setChannelStatesThread.IsAlive)
    7.         {
    8.           _setChannelStatesThread.Abort();
    9.         }
    10.       }
    11.     }
    12.     public void SetChannelStates(IDictionary<int, ITvCardHandler> cards, ICollection<Channel> channels,
    13.                                  IController tvController)
    14.     {
    15.       if (channels == null)
    16.       {
    17.         return;
    18.       }
    19.       AbortChannelStates();
    20.       //call the real work as a thread in order to avoid slower channel changes.
    21.  
    22.          // find all users
    23.       ICollection<IUser> allUsers = GetActiveUsers(cards);
    24.       ThreadStart starter = () => DoSetChannelStates(cards, channels, allUsers, tvController);
    25.  
    26.       lock (_threadlock)
    27.       {
    28.         _setChannelStatesThread = new Thread(starter)
    29.                                     {
    30.                                       Name = "Channel state thread",
    31.                                       IsBackground = true,
    32.                                       Priority = ThreadPriority.Lowest
    33.                                     };
    34.         _setChannelStatesThread.Start();
    35.       }
    36.     }
    37.     }
    best regards SiggiK
     

    Attached Files:

    Last edited by a moderator: June 5, 2014
    • Thank You! Thank You! x 4
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. Holzi
    • Team MediaPortal

    Holzi Super Moderator

    Joined:
    April 21, 2010
    Messages:
    7,927
    Likes Received:
    1,591
    Gender:
    Male
    Location:
    Ba-Wü
    Ratings:
    +2,228 / 8
    Home Country:
    Germany Germany
    Show System Specs
    @mm1352000 do you think this is already fixed in TVE35? :)
     
  4. popy
    • Super User

    popy Super User

    Joined:
    July 3, 2011
    Messages:
    614
    Likes Received:
    83
    Ratings:
    +140 / 2
    Show System Specs
    thx again SiggiK, the patched EXE runs a few days now without any DoSetChannelState exception ;)
    Would be nice to see this patch in 1.8 final.

    pOpY
     
    Last edited: May 30, 2014
  5. Sebastiii
    • Team MediaPortal

    Sebastiii Development Group

    Joined:
    November 12, 2007
    Messages:
    16,204
    Likes Received:
    6,168
    Gender:
    Male
    Location:
    France
    Ratings:
    +10,149 / 9
    Home Country:
    France France
    Show System Specs
    I have see sometimes error in log about log one because of threading aborted but except that seems good :)
     
  6. Sebastiii
    • Team MediaPortal

    Sebastiii Development Group

    Joined:
    November 12, 2007
    Messages:
    16,204
    Likes Received:
    6,168
    Gender:
    Male
    Location:
    France
    Ratings:
    +10,149 / 9
    Home Country:
    France France
    Show System Specs
    Hi,

    @SiggiK :
    There is a comment about the patch from others dev:

    It would be better to either create one thread that idles all the time or use thread pool :p
    Because creating constantly new threads is not an ideal way to handle resources (although it might be even that the current code is using that create & destroy a thread approach instead of using "thread pool, single thread or .NET task" approach
    Not sure about (wakeupEvent.WaitOne) it can be nasty
    So can you try to make another patch with only one worker thread that waits for two things:
    1) Event that some new work has been added to the queue
    2) Command to kill the thread

    When i have copy your patch to the branch, it was needed to change/correct tabs :p, MP use space and 2 instead of 4 :) but if you can provide another version of your patch it could be nice/great.
    Thanks :)
     
  7. SiggiK

    SiggiK Portal Member

    Joined:
    September 26, 2009
    Messages:
    19
    Likes Received:
    6
    Gender:
    Male
    Location:
    Karlsruhe
    Ratings:
    +17 / 0
    Home Country:
    Germany Germany
    Show System Specs
    Hi,


    The best way is

    1) Event that some new work has been added to the queue
    2) Command to kill the thread

    but the Command to kill the thread need a change in TVController. I have made a new version using the thread pool (with space :)).

    best regards SiggiK
     

    Attached Files:

    • Thank You! Thank You! x 1
  8. Sebastiii
    • Team MediaPortal

    Sebastiii Development Group

    Joined:
    November 12, 2007
    Messages:
    16,204
    Likes Received:
    6,168
    Gender:
    Male
    Location:
    France
    Ratings:
    +10,149 / 9
    Home Country:
    France France
    Show System Specs
    Can you post your full file ? :)
    Also if you work on master, can you commit locally and then create a patch (not the diff file) ? thanks :)
    Will be easier to see :)

    Does the new patch is based on master or on your previous patch (i mean on top of it) ?
     
  9. SiggiK

    SiggiK Portal Member

    Joined:
    September 26, 2009
    Messages:
    19
    Likes Received:
    6
    Gender:
    Male
    Location:
    Karlsruhe
    Ratings:
    +17 / 0
    Home Country:
    Germany Germany
    Show System Specs


    The patch is based on master. See attached files.:)
     

    Attached Files:

    • Thank You! Thank You! x 1
  10. Sebastiii
    • Team MediaPortal

    Sebastiii Development Group

    Joined:
    November 12, 2007
    Messages:
    16,204
    Likes Received:
    6,168
    Gender:
    Male
    Location:
    France
    Ratings:
    +10,149 / 9
    Home Country:
    France France
    Show System Specs
    Perfect thanks :)

    So it will replace older patch, so i will rebase the branch against your latest patch and about TVController does it need change too ?
    Can you supply it too ? :)
     
  11. SiggiK

    SiggiK Portal Member

    Joined:
    September 26, 2009
    Messages:
    19
    Likes Received:
    6
    Gender:
    Male
    Location:
    Karlsruhe
    Ratings:
    +17 / 0
    Home Country:
    Germany Germany
    Show System Specs
    All work is done in the ThreadPool, the TVController therefore requires no change.
     
    • Thank You! Thank You! x 1
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!