Click here to Skip to main content
15,922,533 members
Home / Discussions / C#
   

C#

 
QuestionUpate Exe Build Number Pin
Kevin Marois9-Apr-20 14:05
professionalKevin Marois9-Apr-20 14:05 
AnswerRe: Upate Exe Build Number Pin
Richard Deeming14-Apr-20 0:05
mveRichard Deeming14-Apr-20 0:05 
Questiontraversing two lists simultaneously Pin
Pita329-Apr-20 9:11
Pita329-Apr-20 9:11 
AnswerRe: traversing two lists simultaneously Pin
OriginalGriff9-Apr-20 9:29
mveOriginalGriff9-Apr-20 9:29 
AnswerRe: traversing two lists simultaneously Pin
Dave Kreskowiak9-Apr-20 9:31
mveDave Kreskowiak9-Apr-20 9:31 
AnswerRe: traversing two lists simultaneously Pin
Gerry Schmitz9-Apr-20 10:57
mveGerry Schmitz9-Apr-20 10:57 
AnswerRe: traversing two lists simultaneously Pin
James Curran13-Apr-20 1:14
James Curran13-Apr-20 1:14 
Question2 Async/Await Questions Pin
Kevin Marois8-Apr-20 18:10
professionalKevin Marois8-Apr-20 18:10 
One
I have a WPF window which displays a datagrid of Project info. At the top, above the datagrid, are two combo boxes; one for Companies and the other for Project Status. The user can then filter the datagrid by either the Project's company, the Project's status, or both.

When the user opens the window, I want the combo boxes to load asynchronously so the window stays responsive. I want the window to appear, and then load the combobox data. So I have the Window_Loaded event bound to a command, which fires this:
private async Task<bool> WindowLoadedExecuted()
{
    // First load the combo data
    await LoadLists();
    // Now load the projects
    await LoadProjects();
    return true;
}
private async Task<bool> LoadLists()
{
    // Load the Company Headers
    var companyHeaders = await AppCore.BizObject.GetCompanyHeadersAsync();
    CompanyHeaders = new List<CompanyHeaderEntity>(companyHeaders);
    // Load the Project Status lookups
    var projectStatuses = await AppCore.BizObject.GetLookupsAsync(Constants.LookupCategoryProjectStatuses);
    ProjectStatuses = new List<LookupEntity>(projectStatuses);
    return true;
}

The question here is, is there anything wrong with simply returning a Task instead of Task<bool>? Neither of these methods are going to return anything here. I'm asking because I've seen some articles and posts that say it's not a good idea, but I don't see why. Anything wrong with returning Task instead of Task<t> if there's no return value?

Two
Both of the comboboxes above can trigger a requery. By selecting either a Company or a Status to filter by, I want to reload the datagrid. So, in the properties for both, in their getters, I do:
private CompanyHeaderEntity _SelectedCompanyHeader;
public CompanyHeaderEntity SelectedCompanyHeader
{
    get { return _SelectedCompanyHeader; }
    set
    {
        if (_SelectedCompanyHeader != value)
        {
            _SelectedCompanyHeader = value;
            RaisePropertyChanged("SelectedCompanyHeader");

            new Task(async () =>
            {
                await LoadProjects();
            }).Start();
        }
    }
}
To me, this makes sense because selecting a company (instead of none for All), what the user is doing is filtering the list to only those companies. So changing the SelectedCompany property should fire this off.

Yet again, I see posts that seem to discourage this, like this one. Any real reason not to do this? Or is there a better way?

Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.


modified 9-Apr-20 0:26am.

AnswerRe: 2 Async/Await Questions Pin
Richard Deeming9-Apr-20 0:16
mveRichard Deeming9-Apr-20 0:16 
GeneralRe: 2 Async/Await Questions Pin
Kevin Marois9-Apr-20 6:22
professionalKevin Marois9-Apr-20 6:22 
QuestionGetting Text From External Application Pin
KiriGaya-Rye8-Apr-20 13:09
KiriGaya-Rye8-Apr-20 13:09 
QuestionHow to read/load a certificate stored in a JKS (Java key stores) file format, in .NET (C#) Pin
yuvraj vichare8-Apr-20 5:20
yuvraj vichare8-Apr-20 5:20 
AnswerRe: How to read/load a certificate stored in a JKS (Java key stores) file format, in .NET (C#) Pin
jkirkerx8-Apr-20 9:38
professionaljkirkerx8-Apr-20 9:38 
QuestionBackground Data Tables In C# Pin
Member 133258467-Apr-20 0:21
Member 133258467-Apr-20 0:21 
AnswerRe: Background Data Tables In C# Pin
Gerry Schmitz7-Apr-20 6:52
mveGerry Schmitz7-Apr-20 6:52 
AnswerRe: Background Data Tables In C# Pin
Mycroft Holmes7-Apr-20 11:11
professionalMycroft Holmes7-Apr-20 11:11 
AnswerRe: Background Data Tables In C# Pin
#realJSOP8-Apr-20 5:45
professional#realJSOP8-Apr-20 5:45 
GeneralRe: Background Data Tables In C# Pin
Mycroft Holmes8-Apr-20 13:15
professionalMycroft Holmes8-Apr-20 13:15 
GeneralRe: Background Data Tables In C# Pin
#realJSOP9-Apr-20 3:37
professional#realJSOP9-Apr-20 3:37 
QuestionNeed some tips... Sharing a collection of classes for display in a listbox? Pin
DaveHopeDev14-Apr-20 10:58
DaveHopeDev14-Apr-20 10:58 
AnswerRe: Need some tips... Sharing a collection of classes for display in a listbox? Pin
Luc Pattyn4-Apr-20 11:57
sitebuilderLuc Pattyn4-Apr-20 11:57 
GeneralRe: Need some tips... Sharing a collection of classes for display in a listbox? Pin
DaveHopeDev14-Apr-20 22:45
DaveHopeDev14-Apr-20 22:45 
GeneralRe: Need some tips... Sharing a collection of classes for display in a listbox? Pin
Luc Pattyn5-Apr-20 2:11
sitebuilderLuc Pattyn5-Apr-20 2:11 
GeneralRe: Need some tips... Sharing a collection of classes for display in a listbox? Pin
DaveHopeDev15-Apr-20 6:18
DaveHopeDev15-Apr-20 6:18 
GeneralRe: Need some tips... Sharing a collection of classes for display in a listbox? Pin
Luc Pattyn5-Apr-20 6:21
sitebuilderLuc Pattyn5-Apr-20 6:21 

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.