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

SiggiK

Portal Member
September 26, 2009
21
13
Karlsruhe
Home Country
Germany Germany
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:
private void AbortChannelStates()
{

      lock (_threadlock)
      {
       if (_setChannelStatesThread != null && _setChannelStatesThread.IsAlive)
        {
          _setChannelStatesThread.Abort();
        }
      }
    }
    public void SetChannelStates(IDictionary<int, ITvCardHandler> cards, ICollection<Channel> channels,
                                 IController tvController)
    {
      if (channels == null)
      {
        return;
      }
      AbortChannelStates();
      //call the real work as a thread in order to avoid slower channel changes.

         // find all users
      ICollection<IUser> allUsers = GetActiveUsers(cards);
      ThreadStart starter = () => DoSetChannelStates(cards, channels, allUsers, tvController);

      lock (_threadlock)
      {
        _setChannelStatesThread = new Thread(starter)
                                    {
                                      Name = "Channel state thread",
                                      IsBackground = true,
                                      Priority = ThreadPriority.Lowest
                                    };
        _setChannelStatesThread.Start();
      }
    }
    }

best regards SiggiK
 

Attachments

  • ChannelStates.patch
    4.6 KB
Last edited by a moderator:

popy

MP Donator
  • Premium Supporter
  • July 3, 2011
    617
    141
    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:

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    I have see sometimes error in log about log one because of threading aborted but except that seems good :)
     

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    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

    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 :)
     

    SiggiK

    Portal Member
    September 26, 2009
    21
    13
    Karlsruhe
    Home Country
    Germany Germany
    Hi,

    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

    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 :)


    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
     

    Attachments

    • ChannelStates.patch
      3.2 KB

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    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) ?
     

    SiggiK

    Portal Member
    September 26, 2009
    21
    13
    Karlsruhe
    Home Country
    Germany Germany
    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) ?



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

    Attachments

    • 0001-Fix-TVServer-ChannelState.DoSetChannelStates-An-unkn.patch
      3.6 KB
    • ChannelStates.cs.txt
      11.2 KB

    Sebastiii

    Development Group
  • Team MediaPortal
  • November 12, 2007
    16,583
    10,403
    France
    Home Country
    France France
    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 ? :)
     

    Users who are viewing this thread

    Top Bottom