Click here to Skip to main content
15,799,398 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The UI has a "loading" spinner. During the data loading below, the UI is responsive. During the LINQ, it freezes. The computer has 8 cores.

public async static Task Load()
    if (_loader == null)
        _loader = Task.Run(() =>
            using (var ta = new PostformDbTableAdapters.coloursTableAdapter())
                Colours = ta.GetData();
            using (var ta = new PostformDbTableAdapters.finishesTableAdapter())
                Finishes = ta.GetData();
            using (var ta = new PostformDbTableAdapters.image_metaTableAdapter())
                ImageMeta = ta.GetData();
            using (var ta = new PostformDbTableAdapters.laminate_appearancesTableAdapter())
                LaminateAppearances = ta.GetData();
            using (var ta = new PostformDbTableAdapters.laminate_finishesTableAdapter())
                LaminateFinishes = ta.GetData();
            using (var ta = new PostformDbTableAdapters.laminatesTableAdapter())
                Laminates = ta.GetData();
            using (var ta = new PostformDbTableAdapters.manufacturersTableAdapter())
                Manufacturers = ta.GetData();
            using (var ta = new PostformDbTableAdapters.materialsTableAdapter())
                Materials = ta.GetData();
            using (var ta = new PostformDbTableAdapters.patternsTableAdapter())
                Patterns = ta.GetData();
            Swatches = Laminates.Where(lam => lam.lam_man_id != "or").Select( lam => new Laminate
                Id = lam.lam_id,
                Name = lam.lam_name,
                Sku = lam.lam_sku,
                Manufacturer = Manufacturers.FindByman_id(lam.lam_man_id).man_name,
                Finishes = LaminateFinishes.Where(lf => lf.lf_lam_id == lam.lam_id).Select(fin => Finishes.FindByfin_id(fin.lf_fin_id).fin_code).ToArray(),
                ImageId = lam.Islam_img_idNull() ? (int?)null : lam.lam_img_id
            _loader = null;
        await _loader;
        await _loader;

I've tried with and without .AsParellel() on the LINQ.

How can I keep the UI responsive?

1 solution

if you have visual studio 2012 or greater (.Net Framework 4.5 I think) you can use the Async keywords[^]

if not your mostly likely solution will be to put the linq on it's own thread.
Share this answer
Yvan Rodrigues 20-Dec-13 12:59pm    
That's exactly what I'm doing.
bowlturner 20-Dec-13 13:27pm    
Sorry, should have looked closer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900