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

C#

 
GeneralRe: Do something every t seconds Pin
Luc Pattyn28-May-09 17:56
sitebuilderLuc Pattyn28-May-09 17:56 
AnswerRe: Do something every t seconds Pin
Rajesh R Subramanian28-May-09 19:26
professionalRajesh R Subramanian28-May-09 19:26 
AnswerRe: Do something every t seconds Pin
Christian Graus28-May-09 19:27
protectorChristian Graus28-May-09 19:27 
AnswerRe: Do something every t seconds Pin
Mirko198029-May-09 4:19
Mirko198029-May-09 4:19 
Questionreally wierd think Pin
funic28-May-09 14:36
funic28-May-09 14:36 
Questioncreate setup package Pin
sakis2428-May-09 10:50
sakis2428-May-09 10:50 
AnswerRe: create setup package Pin
EliottA28-May-09 11:45
EliottA28-May-09 11:45 
QuestionCleaning up members of a static array property on app exit [modified] Pin
DaveyM6928-May-09 10:42
professionalDaveyM6928-May-09 10:42 
I'm working on a managed MIDI wrapper. Because the only valid devies are those that ae installed, the wrapper exposes a static public property that is an array of devices that are instances of the Input or Output classes (it is not possible for them to create their own instances of these classes).

It's extremely important that any devices used are stopped and closed etc correctly before the program closes.

To do this, I've made the Devices[] property getter return a singleton's static property that is the array, and put the necessary logic in the singleton's destructor.

Is this the best approach?

public class Output
{
    private class Singleton
    {
        static Singleton()
        {
            Output[] result = new Output[GetNumberOfDevices()];
            if (result.Length > 0)
            {
                for (UInt32 u = 0; u < result.Length; u++)
                {
                    result[u] = new Output(u);
                    result[u].SetDeviceCapabilities();
                }
            }
            Devices = result;
        }

        internal static Output[] Devices { get; private set; }

        ~Singleton()
        {
            Output.CloseAll();
        }
    }

    internal Output(UInt32 id)
    {
        // ...
    }
    public static Output[] Devices
    {
        get { return Singleton.Devices; }
    }
    public new static void CloseAll()
    {
        foreach (Output device in Devices)
        device.Close();
    }
    public override void Close()
    {
        // Logic here
    }
    internal static UInt32 GetNumberOfDevices()
    {
        return InteropFunctions.midiOutGetNumDevs();
    }
    internal void SetDeviceCapabilities()
    {
        // ...
    }
    // ...
}


Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)

modified on Thursday, May 28, 2009 4:54 PM

AnswerRe: Cleaning up members of a static array property on app exit Pin
Kythen28-May-09 13:36
Kythen28-May-09 13:36 
GeneralRe: Cleaning up members of a static array property on app exit [modified] Pin
DaveyM6929-May-09 10:36
professionalDaveyM6929-May-09 10:36 
QuestionExecuting Application After Installation (Using Windows Installer) Pin
BlitzPackage28-May-09 9:29
BlitzPackage28-May-09 9:29 
Generalhelp for run length encoding Pin
ali rezaiy28-May-09 8:56
ali rezaiy28-May-09 8:56 
GeneralRe: help for run length encoding Pin
harold aptroot28-May-09 10:59
harold aptroot28-May-09 10:59 
GeneralRe: help for run length encoding Pin
Alan Balkany28-May-09 11:06
Alan Balkany28-May-09 11:06 
QuestionWhat are your preferences for work with databases ADO.net 2.0 LINQ TO SQL or Entity Framework Pin
ToddHileHoffer28-May-09 7:45
ToddHileHoffer28-May-09 7:45 
AnswerRe: What are your preferences for work with databases ADO.net 2.0 LINQ TO SQL or Entity Framework Pin
PIEBALDconsult28-May-09 8:22
mvePIEBALDconsult28-May-09 8:22 
AnswerRe: What are your preferences for work with databases ADO.net 2.0 LINQ TO SQL or Entity Framework Pin
Henry Minute28-May-09 8:43
Henry Minute28-May-09 8:43 
GeneralRe: What are your preferences for work with databases ADO.net 2.0 LINQ TO SQL or Entity Framework Pin
ScottM128-May-09 20:21
ScottM128-May-09 20:21 
QuestionDraggable WinForm w/ Docked Control Problem Pin
baehoo28-May-09 7:42
baehoo28-May-09 7:42 
QuestionUsing sortedlist or sorteddictionary Pin
michaelgr128-May-09 7:10
michaelgr128-May-09 7:10 
AnswerRe: Using sortedlist or sorteddictionary Pin
Ennis Ray Lynch, Jr.28-May-09 7:23
Ennis Ray Lynch, Jr.28-May-09 7:23 
GeneralRe: Using sortedlist or sorteddictionary Pin
michaelgr128-May-09 7:24
michaelgr128-May-09 7:24 
GeneralRe: Using sortedlist or sorteddictionary Pin
Ennis Ray Lynch, Jr.28-May-09 7:29
Ennis Ray Lynch, Jr.28-May-09 7:29 
GeneralRe: Using sortedlist or sorteddictionary Pin
DaveyM6928-May-09 7:31
professionalDaveyM6928-May-09 7:31 
AnswerRe: Using sortedlist or sorteddictionary Pin
Luc Pattyn28-May-09 7:29
sitebuilderLuc Pattyn28-May-09 7:29 

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.