Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

C# WPF UI update is very slow

$
0
0

Hi,

I have a WPF application wherein I have a canvas and three images on it to display the xy, yz and xz plane of a volume.

I just run a for loop from i = 0 to z-1 and calculate each xy, yz and xz plane information and display in writeablebitmaps on the screen.  The process is very slow although I made separate threads and invoked them using each image element's dispatcher.

an example of my code is as stubbed below:

// Main Window
public MainWindow()
{
    InitializeComponent();
    InitializeDisplay();

    gFiles = Directory.GetFiles(gkDirectory);

    vol = new int[512, 512, 600];

    DisplayTimer = new System.Windows.Threading.DispatcherTimer();
    DisplayTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);
    DisplayTimer.Tick += new EventHandler(DisplayTimer_Tick);
            DisplayTimer.Start();

        }

        // Timer events
        void DisplayTimer_Tick(object sender, EventArgs e)
        {
            DisplayTimer.Stop();
            if (i == 600)
            {
                z = i - 1;
                x = 256;
                y = 256;
                return;
            }

            slices = gFiles.Length;
            string myFile = gFiles[i];

            // Read the file

            int[,] xy = GetPixelData();
            for (int m = 0; m < 512; m++)
            {
                for (int n = 0; n < 512; n++)
                {
                    vol[n, m, i] = Axial[n, m];
                }
            }

            int[,] xz = new int[600, 512];

            int[,] yz = new int[600, 512];


            Thread t1 = new Thread(new ThreadStart(
                delegate()
                {
                    this.Dispatcher.Invoke(new ImageUpdate(DisplayIm), System.Windows.Threading.DispatcherPriority.Normal, xz, "xz");
                }));
            t1.IsBackground = true;
            t1.Start();

            Thread t2 = new Thread(new ThreadStart(
                delegate()
                {
                    this.Dispatcher.Invoke(new ImageUpdate(DisplayIm), System.Windows.Threading.DispatcherPriority.Normal, xy, "xy");
                }));
            t2.IsBackground = true;
            t2.Start();

            Thread t3 = new Thread(new ThreadStart(
                delegate()
                {
                    this.Dispatcher.Invoke(new ImageUpdate(DisplayIm), System.Windows.Threading.DispatcherPriority.Normal, yz, "yz");
                }));
            t3.IsBackground = true;
            t3.Start();

            i++;
            DisplayTimer.Start();

        }
Can someone please help me with this?


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>