Click here to Skip to main content
15,887,267 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: Unmanaged callback, Dispose issue Pin
DaveyM6914-Aug-10 9:31
professionalDaveyM6914-Aug-10 9:31 
Questionhow to session value in a page. Pin
Mubeen.asim12-Aug-10 21:38
Mubeen.asim12-Aug-10 21:38 
AnswerRe: how to session value in a page. Pin
Jens Meyer12-Aug-10 22:10
Jens Meyer12-Aug-10 22:10 
GeneralRe: how to session value in a page. Pin
Mubeen.asim12-Aug-10 23:17
Mubeen.asim12-Aug-10 23:17 
QuestionResize problem for drawn rectangle on the picture box? Pin
Nivas8212-Aug-10 20:27
Nivas8212-Aug-10 20:27 
AnswerRe: Resize problem for drawn rectangle on the picture box? Pin
Luc Pattyn13-Aug-10 2:05
sitebuilderLuc Pattyn13-Aug-10 2:05 
GeneralRe: Resize problem for drawn rectangle on the picture box? Pin
Nivas8217-Aug-10 20:30
Nivas8217-Aug-10 20:30 
GeneralRe: Resize problem for drawn rectangle on the picture box? Pin
Luc Pattyn18-Aug-10 1:41
sitebuilderLuc Pattyn18-Aug-10 1:41 
GeneralRe: Resize problem for drawn rectangle on the picture box? Pin
Nivas8223-Aug-10 2:12
Nivas8223-Aug-10 2:12 
AnswerRe: Resize problem for drawn rectangle on the picture box? Pin
Luc Pattyn23-Aug-10 2:16
sitebuilderLuc Pattyn23-Aug-10 2:16 
GeneralRe: Resize problem for drawn rectangle on the picture box? Pin
Nivas8223-Aug-10 23:09
Nivas8223-Aug-10 23:09 
GeneralRe: Resize problem for drawn rectangle on the picture box? Pin
Nivas8220-Oct-10 21:30
Nivas8220-Oct-10 21:30 
QuestionHow to load a referenced dll from specified location not GAC? Pin
Jack2009512-Aug-10 16:57
Jack2009512-Aug-10 16:57 
AnswerRe: How to load a referenced dll from specified location not GAC? Pin
PIEBALDconsult12-Aug-10 17:46
mvePIEBALDconsult12-Aug-10 17:46 

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.