[Mono-list] Unhandled Exception: System.EntryPointNotFoundException:

William Huskey william.huskey at gmail.com
Mon Mar 19 18:39:50 EDT 2007


I have this program that uses kernel32.dll and I have linked the wine
kernel32.dll to help this, but I get the same error as below, is this not
doable, It was compile using Mono 2.0 on windows and runs under mono on
windows. is there a cross platform way of using
System.Runtime.InteropServices ?

Thanks for your time


Initializing Simulators...rting Simulation...

Unhandled Exception: System.EntryPointNotFoundException:
QueryPerformanceFrequency
  at (wrapper managed-to-native)
RTSTest.HiPerfTimer:QueryPerformanceFrequency (long&)
  at RTSTest.HiPerfTimer..ctor () [0x00000]
  at RTSTest.MainClass.Main (System.String[] args) [0x00000]


the code is as follows



using System;
using System.Collections.Generic;
using System.Collections;
using System.Threading;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.ComponentModel;

namespace RTSTest
{
    class MainClass
    {
        private static List<Simulator> Simulators = new List<Simulator>();

        const int SimulatorCount = 64;
        const int IterationCount = 100;

        public static void Main(string[] args)
        {
            Console.WriteLine("Simulator Timing Prototype Application");
            Console.WriteLine("by Andrew Flanagan, March 15, 2007\n");
            Console.WriteLine("Initializing Simulators...");

            AutoResetEvent[] doneEvents = new
AutoResetEvent[SimulatorCount];

            for (int i = 0; i < SimulatorCount; i++)
            {
                doneEvents[i] = new AutoResetEvent(false);
                Simulators.Add(new Simulator("Sim" + (i + 1),
doneEvents[i]));
            }

            Console.WriteLine("Starting Simulation...");

            //Start the HPT
            HiPerfTimer mainLoopTimer = new HiPerfTimer();

            mainLoopTimer.Start();

            //Run for 10 iterations
            for (int i = 0; i < IterationCount; i++)
            {
                HiPerfTimer subLoopTimer = new HiPerfTimer();

                subLoopTimer.Start();

                Console.WriteLine("\nStarting iteration " + (i + 1) + ":");
                foreach (Simulator sim in Simulators)
                {
                    ThreadPool.QueueUserWorkItem(sim.ThreadPoolCallback,
sim.Name);
                }

                WaitHandle.WaitAll(doneEvents);

                subLoopTimer.Stop();

                Console.WriteLine("All threads have completed.");

                Console.WriteLine("Here are the results:");
                foreach (Simulator sim in Simulators)
                {
                    Console.WriteLine("++SampleOutput is " +
sim.keyValuePair["SampleOutput"]);
                }

                Console.WriteLine("Total time for this iteration: {0}ms",
subLoopTimer.RoundedDuration);
            }

            mainLoopTimer.Stop();

            Console.WriteLine("\nDone.");
            Console.WriteLine("\nTotal run time: {0}ms",
mainLoopTimer.RoundedDuration);


            Console.ReadLine();
        }
    }

    #region Simulator Class

    class Simulator
    {
        public Dictionary<string, object> keyValuePair;

        private string SimulatorName;

        public string Name {get {return SimulatorName; }}

        private AutoResetEvent doneEvent;

        public Simulator(string Name, AutoResetEvent doneEvent)
        {
            keyValuePair = new Dictionary<string, object>();

            keyValuePair.Add("SampleOutput", 0);

            this.SimulatorName = Name;
            this.doneEvent = doneEvent;
        }

        public void ThreadPoolCallback(Object threadContext)
        {
            HiPerfTimer threadLoopTimer = new HiPerfTimer();
            threadLoopTimer.Start();

            string threadName = (string)threadContext;
           Console.WriteLine("++thread {0} started...", threadName);

            RandomNumberGenerator rng = RandomNumberGenerator.Create();
            byte[] byteArray = new byte[10];
            rng.GetNonZeroBytes(byteArray);

            int randomSampleOutput = 0;
            for (int i = 0; i < 4; i++) {
                int shift = (4 - 1 - i) * 8;
                randomSampleOutput += (byteArray[i] & 0x000000FF) << shift;
            }

            Random rnd = new Random(randomSampleOutput);

            int SleepTime = Convert.ToInt16(rnd.NextDouble() * 5000);

            Thread.Sleep(SleepTime);

            this.keyValuePair["SampleOutput"] = randomSampleOutput;

            threadLoopTimer.Stop();

            Console.WriteLine("++thread {0} finished. (Simulated Processing
Time took {1}ms)", threadName, threadLoopTimer.RoundedDuration);

            this.doneEvent.Set();
        }
    }

    #endregion

    #region High-Performance Timer Class

    public class HiPerfTimer
    {
        [DllImport("Kernel32.dll")]
        private static extern bool QueryPerformanceCounter(out long
lpPerformanceCount);
        [DllImport("Kernel32.dll")]
        private static extern bool QueryPerformanceFrequency(out long
lpFrequency);

        private long startTime ;
        private long stopTime;
        private long freq;

        /// <summary>
        /// ctor
        /// </summary>
        public HiPerfTimer()
        {
            startTime = 0;
            stopTime = 0;
            freq =0;
            if (QueryPerformanceFrequency(out freq) == false)
            {
                throw new Win32Exception(); // timer not supported
            }
        }

        /// <summary>
        /// Start the timer
        /// </summary>
        /// <returns>long - tick count</returns>
        public long Start()
        {
            QueryPerformanceCounter(out startTime);
            return startTime;
        }

        /// <summary>
        /// Stop timer
        /// </summary>
        /// <returns>long - tick count</returns>
        public long Stop()
        {
            QueryPerformanceCounter(out stopTime);
            return stopTime;
        }

        /// <summary>
        /// Return the duration of the timer (in seconds)
        /// </summary>
        /// <returns>double - duration</returns>
        public double Duration
        {
            get
            {
                return (double)(stopTime - startTime) / (double) freq;
            }
        }

        /// <summary>
        /// Return the duration of the timer (in milliseconds) but rounded
nicely
        /// </summary>
        /// <returns>double - duration</returns>
        public double RoundedDuration
        {
            get
            {
                return Math.Round((double)(stopTime - startTime) / (double)
freq, 3) * 1000;
            }
        }

        /// <summary>
        /// Frequency of timer (no counts in one second on this machine)
        /// </summary>
        ///<returns>long - Frequency</returns>
        public long Frequency
        {
            get
            {
                QueryPerformanceFrequency(out freq);
                return freq;
            }
        }
    }

    #endregion
}






-- 
William S. Huskey

UNIX Systems Engineer

Maritime Systems Solutions Division

SAIC

Tel: 425-267-5643

Email: huskeyw at saic.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20070319/7b2223e3/attachment.html 


More information about the Mono-list mailing list