80 lines
2.6 KiB
C#
80 lines
2.6 KiB
C#
//=================================================================
|
|
// ThreadedBindingList.cs
|
|
//=================================================================
|
|
// PowerSDR is a C# implementation of a Software Defined Radio.
|
|
// Copyright (C) 2003-2013 FlexRadio Systems
|
|
//
|
|
// This program is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU General Public License
|
|
// as published by the Free Software Foundation; either version 2
|
|
// of the License, or (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
//
|
|
// You may contact us via email at: gpl@flexradio.com.
|
|
// Paper mail may be sent to:
|
|
// FlexRadio Systems
|
|
// 4616 W. Howard Lane Suite 1-150
|
|
// Austin, TX 78728
|
|
// USA
|
|
//=================================================================
|
|
// taken from http://stackoverflow.com/questions/455766/how-do-you-correctly-update-a-databound-datagridview-from-a-background-thread
|
|
//=================================================================
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Threading;
|
|
|
|
namespace PowerSDR
|
|
{
|
|
public class ThreadedBindingList<T> : BindingList<T>
|
|
{
|
|
SynchronizationContext ctx = SynchronizationContext.Current;
|
|
protected override void OnAddingNew(AddingNewEventArgs e)
|
|
{
|
|
//SynchronizationContext ctx = SynchronizationContext.Current;
|
|
if (ctx == null)
|
|
{
|
|
BaseAddingNew(e);
|
|
}
|
|
else
|
|
{
|
|
ctx.Send(delegate
|
|
{ BaseAddingNew(e); }, null);
|
|
}
|
|
}
|
|
|
|
void BaseAddingNew(AddingNewEventArgs e)
|
|
{
|
|
base.OnAddingNew(e);
|
|
}
|
|
|
|
protected override void OnListChanged(ListChangedEventArgs e)
|
|
{
|
|
//SynchronizationContext ctx = SynchronizationContext.Current;
|
|
if (ctx == null)
|
|
{
|
|
BaseListChanged(e);
|
|
}
|
|
else
|
|
{
|
|
ctx.Send(delegate
|
|
{ BaseListChanged(e); }, null);
|
|
}
|
|
}
|
|
|
|
void BaseListChanged(ListChangedEventArgs e)
|
|
{
|
|
base.OnListChanged(e);
|
|
}
|
|
}
|
|
}
|