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

C#

 
AnswerRe: Update Peoplesoft inventory table by an Dotnet application PinPopular
Rajesh R Subramanian28-May-09 19:21
professionalRajesh R Subramanian28-May-09 19:21 
QuestionRegular expression for 0 to 1000 Pin
velkumar_in28-May-09 19:02
velkumar_in28-May-09 19:02 
AnswerRe: Regular expression for 0 to 1000 Pin
Christian Graus28-May-09 19:26
protectorChristian Graus28-May-09 19:26 
GeneralRe: Regular expression for 0 to 1000 Pin
outerhell28-May-09 21:25
outerhell28-May-09 21:25 
GeneralRe: Regular expression for 0 to 1000 Pin
Nagy Vilmos28-May-09 21:53
professionalNagy Vilmos28-May-09 21:53 
AnswerRe: Regular expression for 0 to 1000 Pin
ScottM128-May-09 20:22
ScottM128-May-09 20:22 
AnswerRe: Regular expression for 0 to 1000 Pin
V.28-May-09 20:22
professionalV.28-May-09 20:22 
AnswerRe: Regular expression for 0 to 1000 Pin
Guffa28-May-09 20:50
Guffa28-May-09 20:50 
QuestionSearch Engine Optimization Pin
Member 426027028-May-09 18:23
Member 426027028-May-09 18:23 
AnswerRe: Search Engine Optimization Pin
Baran M28-May-09 18:44
Baran M28-May-09 18:44 
AnswerRe: Search Engine Optimization Pin
Eddy Vluggen28-May-09 21:03
professionalEddy Vluggen28-May-09 21:03 
QuestionDo something every t seconds Pin
Quake2Player28-May-09 16:41
Quake2Player28-May-09 16:41 
AnswerRe: Do something every t seconds Pin
Luc Pattyn28-May-09 17:09
sitebuilderLuc Pattyn28-May-09 17:09 
GeneralRe: Do something every t seconds Pin
Quake2Player28-May-09 17:45
Quake2Player28-May-09 17:45 
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 

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.