Click here to Skip to main content
15,905,558 members
Home / Discussions / C#
   

C#

 
QuestionHow to update picturebox with image on from queue on runtime ? ( code attached ) Pin
Yanshof13-Aug-10 4:52
Yanshof13-Aug-10 4:52 
AnswerRe: How to update picturebox with image on from queue on runtime ? ( code attached ) Pin
Luc Pattyn13-Aug-10 5:02
sitebuilderLuc Pattyn13-Aug-10 5:02 
Questioncalling Form from another Form and office access database. Pin
marwan_siala13-Aug-10 4:17
marwan_siala13-Aug-10 4:17 
AnswerRe: calling Form from another Form and office access database. Pin
dan!sh 13-Aug-10 4:21
professional dan!sh 13-Aug-10 4:21 
GeneralRe: calling Form from another Form and office access database. Pin
marwan_siala13-Aug-10 4:28
marwan_siala13-Aug-10 4:28 
AnswerRe: calling Form from another Form and office access database. Pin
OriginalGriff13-Aug-10 4:21
mveOriginalGriff13-Aug-10 4:21 
GeneralRe: calling Form from another Form and office access database. Pin
marwan_siala13-Aug-10 4:26
marwan_siala13-Aug-10 4:26 
QuestionData source selection for C# win app Pin
Eduard Keilholz13-Aug-10 3:34
Eduard Keilholz13-Aug-10 3:34 
AnswerRe: Data source selection for C# win app Pin
dan!sh 13-Aug-10 3:56
professional dan!sh 13-Aug-10 3:56 
AnswerRe: Data source selection for C# win app Pin
Dr.Walt Fair, PE13-Aug-10 5:02
professionalDr.Walt Fair, PE13-Aug-10 5:02 
AnswerRe: Data source selection for C# win app Pin
Dan Mos13-Aug-10 7:35
Dan Mos13-Aug-10 7:35 
Questionsplit issue Pin
varsh1213-Aug-10 2:03
varsh1213-Aug-10 2:03 
AnswerRe: split issue Pin
Luc Pattyn13-Aug-10 2:08
sitebuilderLuc Pattyn13-Aug-10 2:08 
AnswerRe: split issue Pin
Ian Shlasko13-Aug-10 2:58
Ian Shlasko13-Aug-10 2:58 
GeneralRe: split issue Pin
Luc Pattyn13-Aug-10 3:38
sitebuilderLuc Pattyn13-Aug-10 3:38 
GeneralRe: split issue Pin
Ian Shlasko13-Aug-10 4:25
Ian Shlasko13-Aug-10 4:25 
QuestionUnmanaged callback, Dispose issue Pin
DaveyM6912-Aug-10 23:04
professionalDaveyM6912-Aug-10 23:04 
AnswerRe: Unmanaged callback, Dispose issue Pin
Luc Pattyn13-Aug-10 1:51
sitebuilderLuc Pattyn13-Aug-10 1:51 
GeneralRe: Unmanaged callback, Dispose issue Pin
DaveyM6913-Aug-10 2:17
professionalDaveyM6913-Aug-10 2:17 
AnswerRe: Unmanaged callback, Dispose issue Pin
Luc Pattyn13-Aug-10 2:46
sitebuilderLuc Pattyn13-Aug-10 2:46 
GeneralRe: Unmanaged callback, Dispose issue Pin
DaveyM6913-Aug-10 4:35
professionalDaveyM6913-Aug-10 4:35 
GeneralRe: Unmanaged callback, Dispose issue Pin
DaveyM6914-Aug-10 8:30
professionalDaveyM6914-Aug-10 8:30 
Hi Luc,

I've done alot of experimentation with this over the last 24 hours which has lead to trying SafeHandles and all kinds of stuff.

It seems the key to the solution is:

Luc Pattyn wrote:
XFunctionality would also contain a static List<XFunctionality>


In the MidiDevice base class I have created two static Lists which are filled in a static constructor.
C#
protected static List<MidiInput> inputs;
protected static List<MidiOutput> outputs;

static MidiDevice()
{
    uint inputCount = NativeMethods.midiInGetNumDevs();
    inputs = new List<MidiInput>((int)inputCount);
    if (inputCount > 0)
        for (uint u = 0; u < inputCount; u++)
            inputs.Add(new MidiInput(u));
    uint outputCount = NativeMethods.midiOutGetNumDevs();
    outputs = new List<MidiOutput>((int)outputCount);
    if (outputCount > 0)
        for (uint u = 0; u < outputCount; u++)
            outputs.Add(new MidiOutput(u));
}

which are exposed as ReadOnlyCollections in the derived classes.
C#
public static ReadOnlyCollection<MidiOutput> Outputs
{
    get { return outputs.AsReadOnly(); }
}

This seems to be enough to trigger the finalizer for each MidiDevice instance on application close where I can call Close (I'm using GC.KeepAlive(this) as an added safety net) and the callback also happens.
C#
~MidiDevice()
{
    Close();
    GC.KeepAlive(this);
}

This is working perfectly with the hardware I'm using for testing at the moment!
Any further thoughts or comments?
Dave

If this helped, please vote & accept answer!


Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

GeneralRe: Unmanaged callback, Dispose issue Pin
Luc Pattyn14-Aug-10 8:43
sitebuilderLuc Pattyn14-Aug-10 8:43 
GeneralRe: Unmanaged callback, Dispose issue Pin
DaveyM6914-Aug-10 9:07
professionalDaveyM6914-Aug-10 9:07 
GeneralRe: Unmanaged callback, Dispose issue Pin
Luc Pattyn14-Aug-10 9:19
sitebuilderLuc Pattyn14-Aug-10 9:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.