Program in WPF C# using .mdf database with LINQtoSQL freezes for a bit when I load the database

Hello everyone, I have the following code that I run inside a button clicked event in order to compare the username and password
given by the user.
public static bool isAuthenticated(string Username, string Password)
//Open a connection with the databas
using (WHDataDataContext db = new WHDataDataContext())
//Compare the Username and the password and return the result
return db.Users.Any(check => check.Username == Username && check.Password == Cryptographer.Encrypt(Password));
and I use the code like this
private void Button_Click(object sender, RoutedEventArgs e)
//Access the DatabaseControls class and use the isAuthenticated Method
if (DatabaseControls.isAuthenticated(UserBox.Text, PasswordBox.Password))
DialogResult = true; //if the result is true close the dialog
DatabaseControls.setConnected(UserBox.Text, true);
else if (UserBox.Text == "" || PasswordBox.Password == "")
//if the user didn't fill any of the requested boxes show warning
MessageBox.Show(this, "Το όνομα χρήστη και ο κωδικός δεν μπορούν να είναι άδεια", "Προσοχή!", MessageBoxButton.OK, MessageBoxImage.Warning);
if (UserBox.Text == "") UserBox.Focus(); //if the UserBox was empty focus it
else PasswordBox.Focus(); //else focus the PasswordBox
else
//if the result is false show an error and select the UserBox
MessageBox.Show(this, "Δώσατε λάθος στοιχεία, παρακαλώ προσπαθήστε ξανά!", "Σφάλμα", MessageBoxButton.OK, MessageBoxImage.Error);
UserBox.SelectAll();
UserBox.Focus();
My problem is that when I hit the button the program freezes for a moment and the it responds.
I have used this code on a c# application with .sdf file (SQL CE) and I haven't experienced this issue.
I have already tried using threads (Task.StartNew and BackgroundWorker) but I got the same result.
I have also created the DB Context once instead of using (DBContext db = new DBContext()) everytime and I still got the same result.
Could anyone please help?

Async features should have addressed it, you may not just be doing things properly.
Try implementing things this way:
1. If you're not using EF 6 which is the latest version then update your project first. This will allow you to take advantage of EF's async methods.
2. Implement your isAuthenticated method in this manner:
public static Task<bool> isAuthenticatedAsync(string Username, string Password)
//Open a connection with the databas
using (WHDataDataContext db = new WHDataDataContext())
//Compare the Username and the password and return the result
return db.Users.AnyAsync(check => check.Username == Username && check.Password == Cryptographer.Encrypt(Password));
3. Implement your Button_Click event handler in this manner:
private async void Button_Click(object sender, RoutedEventArgs e)
//Access the DatabaseControls class and use the isAuthenticated Method
var authenticated = await DatabaseControls.isAuthenticatedAsync(UserBox.Text, PasswordBox.Password);
if (authenticated)
DialogResult = true; //if the result is true close the dialog
DatabaseControls.setConnected(UserBox.Text, true);
else if (UserBox.Text == "" || PasswordBox.Password == "")
//if the user didn't fill any of the requested boxes show warning
MessageBox.Show(this, "Το όνομα χρήστη και ο κωδικός δεν μπορούν να είναι άδεια", "Προσοχή!", MessageBoxButton.OK, MessageBoxImage.Warning);
if (UserBox.Text == "") UserBox.Focus(); //if the UserBox was empty focus it
else PasswordBox.Focus(); //else focus the PasswordBox
else
//if the result is false show an error and select the UserBox
MessageBox.Show(this, "Δώσατε λάθος στοιχεία, παρακαλώ προσπαθήστε ξανά!", "Σφάλμα", MessageBoxButton.OK, MessageBoxImage.Error);
UserBox.SelectAll();
UserBox.Focus();

Similar Messages

  • Hi everyone,,i bought a used iphone 5 with iOs 7.0.3. i want to delete the icloud account and add mine. I have sent an e-mail to the current account being used in my iphone. How can i get rid of this account plzzz help me out

    Hi everyone,,i bought a used iphone 5 with iOs 7.0.3. i want to delete the icloud account and add mine. I have sent an e-mail to the current account being used in my iphone. How can i get rid of this account plzzz help me ou

    no i called the store owner from whom i bought it. he was like i will check in records and if there is something i will let u know...he was like send an e-mail its better so if it was stolen so the shopkeeper wouldnt let me to e-mail to the owner

  • I tried for update but when i saw the screen its showing an arrow with a USB cable towards itunes icon, and now i'm not able to do anything, i also tried to connect ipad through my laptop but no use

    i tried for update but when i saw the screen its showing an arrow with a USB cable towards itunes icon, and now i'm not able to do anything, i also tried to connect ipad through my laptop but no use

    That message means that you have to restore the iPad now. There was a problem with the update. So connect the iPad to your computer and restore your iPad.
    You can read bout it here.
    http://support.apple.com/kb/ht1414
    If that does not work you will need recovery mode. You can read about it here.
    http://support.apple.com/kb/ht4097
    Or you can follow these Recovery Mode Instructions
    Disconnect the USB cable from the iPad, but leave the other end of the cable connected to your computer's USB port.
    Turn off iPad: Press and hold the Sleep/Wake button for a few seconds until the red slider appears, then slide the slider. Wait for iPad to turn off.
    If you cannot turn off iPad using the slider, press and hold the Sleep/Wake and Home buttons at the same time. When the iPad turns off, release the Sleep/Wake and Home buttons.
    While pressing and holding the Home button, reconnect the USB cable to iPad. When you reconnect the USB cable, iPad should power on.
    Continue holding the Home button until you see the "Connect to iTunes" screen. When this screen appears you can release the Home button.
    If necessary, open iTunes. You should see the recovery mode alert that iTunes has detected an iPad in recovery mode.
    Use iTunes to restore iPad.

  • TS2756 iam using iphone 4S with win 7 PC and i cannot connect to the internet through my phone but i tried with my other 4S and it works but what should i do for the first iphone 4S???

    iam using iphone 4S with win 7 PC and i cannot connect to the internet through my phone but i tried with my other 4S and it works but what should i do for the first iphone 4S???
    as i said i have two iphone 4S,,,,,
    1st one --- has os 5.1
    2nd one has os 6.0
    i tried 2nd one with carrier reliance gsm nd it works with that personal hotspot setting using USB...
    but i want to connect the first 4S with carrier TATA DOCOMO GSM but its not working with the same USB feature????
    plz reply asap...!!!
    thnxxx in advance!!!

    If not this:
    iOS: Wi-Fi or Bluetooth settings grayed out or dim
    One user reported that placing the iPod in the freezer fixed the problem.
    Also heating sometimes works. See:
    Why can't I select my wifi settings?
    A trick that works frequently with iPhones:
    Settings > AirPlane Mode ON, Do Not Disturb ON
    Power down and wait 5-10 minutes
    Power up
    Settings > AirPlane Mode OFF, Do Not Disturb OFF
    If not successful, an appointment at the Genius Bar of an Apple store is usually in order.
    Apple Retail Store - Genius Bar
    Then:
    Does the iOS device connect to other networks? See other networks? If yes that tends to indicate a problem with your network.
    Does the iOS device see the network?
    Any error messages?
    Do other devices now connect?
    Did the iOS device connect before?
    Try the following to rule out a software problem:                
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Power off and then back on your router
    .- Reset network settings: Settings>General>Reset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - Wi-Fi: Unable to connect to an 802.11n Wi-Fi network      
    - iOS: Recommended settings for Wi-Fi routers and access points
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    If still problem and it does not connect to any networks make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar

  • I am using i padmini with retina display. i was curious to know if the pdf files saved on adobe reader app are safe from any hacking

    I am using i padmini with retina display. i was curious to know if the pdf files saved on adobe reader app are safe from any hacking

    If they are saved on your iPad, they are as safe as anything else.
    Barry

  • How to use Mulitple DAQs with a single triggered event on only one of the DAQs

    I have three PXI6115 and would like to tie all these to a single triggered event on one of the DAQs. I've scaned the examples and any assistance would be greatly appreciated....

    TCjr,
    Please refer to your other post:
    How to use Multiple DAQs with a single triggered event on only one of the DAQs

  • Used wrong charger with ipod classic, now it wont turn on, displays the low battery icon even though its connected to the wright adapter

    used wrong charger with ipod classic, now it wont turn on, displays the low battery icon even though its connected to the wright adapter.
    Can anyone help ?
    please?

    WHow long have you left it to charge?  Have you tried resetting it after a short period of time to see if that can help jumpstart the charging process? To do this, press and hold both the Select/Center and Menu buttons together long enough for the Apple logo to appear.
    B-rock

  • TS3367 My partner has the Iphone 5 and I am using a MacBook with version 1.0.2. When using the face time app to call him he says that cam freezes and he is unable to hear me. Any ideas of the problem and and ideas for resolving the issue?

    My partner has the Iphone 5 and I am using a MacBook with version 1.0.2. When using the face time app to call him he says that cam freezes and he is unable to hear me. Any ideas of the problem and and ideas for resolving the issue?

    Had the same problem, the only fault and the reason why it happend is a bad wifi connection!
    Could ofc be something else, but thats my two cents!

  • HT1386 we are using same laptop with my wife for our 2 iphones and when sincronizing, she's getting my apps and is requested for my apple id and password when getting a new app on her device. How can i fix that issue?

    we are using same laptop with my wife for our 2 iphones and when sincronizing, she's getting my apps and is requested for my apple id and password when getting a new app on her device. How can i fix that issue?

    Each phone needs to set its own sync settings on the various tabs in iTunes.  On the Apps tab, for example, uncheck the apps that you don't want on the phone being synced.  This article may also be of interest: http://gigaom.com/apple/itunes-101-multiple-devices-one-itunes-account/.
    You can change the Apple ID used for purchasing on her phone by going to Settings>Store>Apple ID, tap the ID shown, sign out, sign back in using her Apple ID.  However, be aware that if she has any apps on her phone purchased with your Apple ID she will still be prompted to enter the password associated with this ID for all future updates of these apps.  This is because apps are permanently tied to the Apple ID used to purchase them, regardless of the ID in Settings>Store.

  • When I try to load Indesign, an error message appears: "the exploitation system you are using is no longer taking responsibility with Indesign". What can I do to load the software?

    When I try to load Indesign, an error message appears: "the exploitation system you are using is no longer taking responsibility with Indesign". What can I do to load the software?

    Do you have a license for InDesign?

  • How use set up with office 2011 for mac as I did keep tried put download but it's always 'update' download. I want get start set up new office 2011 for mac? please help me

    how use set up with office 2011 for mac as I did keep tried put download but it's always 'update' download. I want get start set up new office 2011 for mac? please help me

    You must be using an update CD.  You need the software that has the full version first - install that, then you can use the update one if needed. I know, cuz I made the same mistake - lol

  • I'm using iphone 4s with ios6, but why can't make facetime over the cellular networks?thanx for the answer

    i'm using iphone 4s with ios6, but why can't make facetime over the cellular networks?thanx for the answer

    Depends on your carrier and data plan.
    With ATT in the US for example, you can FaceTime via ATT's cellular network if you have a shared data plan only.

  • I was just wondering if I can use time capsule with my iphone for both back up and to access the hard drive on the capsule?

    I was just wondering if I can use time capsule with my iphone for both back up and to access the hard drive on the capsule?

    I don't think backup is supported but you may be able to access the TC's internal drive, from the iPhone, with an application like: NetPortal
    Note: I haven't actually tried this app, so if someone else has and was successful in accessing the TC's drive they can certainly chime in.
    Follow-up. Just downloaded and installed this app ... and I can now verify that it, indeed, can access both my TC's internal and externally attached USB HDD.

  • I forgot to turn off the FIND MY iPhone appplication before i reset up the phone, Now it's asking me to verify with apple or icloud ID but when i entered the same ID which was registered as apple ID, It says INCORRECT. It's been already 03 days

    I have forgotten to turn off the FIND MY iPhone appplication before i reset up the phone, Now it's asking me to verify with apple or icloud ID but when i entered the same ID which was registered with itune & icloud, It says INCORRECT. It's been already 03 days, I am asking help with apple care centre, UAE, Head qurter, UK, USA but they are just sending me a link to reset up which still doesn't work. I am really dissapointed that i have wasted my 700 US dollar. Is it true that i can't use anymore this iPhone if i can't unlock? or there is any one to help in Dubai, Since i am staying in Dubai. I had called Dubai authorised care cantre. They asked my apple serial & IMEI number, They said ' the serial number is based on USA support but i bought in retail shop in UAE, They are also helpless. I am really unhappy with Apple sevice what they provide the customer. If it's so complicated the i wouldnt buy iPhone. Why they can't reset up my iphone like new mobile using their software. Please help me if anyone of you have solution for this. I am really sad that i wasted 700 USD. Can someone help me??

    Thank you Chris for your concern. But It doesnt go through.
    I tried through iForget,
    01.
    Select your authentication method.
    Email authentication: To access your information, we will send an email to the address(es) on file for you.
    Answer security questions: To access your information, you will need to answer the security question(s) provided when you originally created your Apple ID.
    02.
    Email has been sent.
    When you receive your sign in information, follow the directions in the email to reset your password.
    But
    I m not receiving any authentication email even it says that email has been sent, & trtied to verify my birth date & all then it says
    Password Reset
    Your Apple ID password has been reset.
    Return to My Apple ID
    After all, I am just putting the same id & password, It says INCORRECT.
    "Is it my problem is not clear to you all? Please help me. Thank you!
    Regards
    Sujan

  • I am running windows xp. Trying to download latest version of iTunes and get error message: Microsoft Visual C  Rundtime Library. Runtime Error. Program:C\ProgramFiles\iTunes\iTunes.exe. R6034 An appliction has made an attempt to load the C runtime librar

    I am running windows xp. Trying to download latest version of iTunes and get error message: Microsoft Visual C  Rundtime Library. Runtime Error. Program:C\ProgramFiles\iTunes\iTunes.exe. R6034 An appliction has made an attempt to load the C runtime library incorrectly. Please contact the appliction's support team for more information.
    2nd/ message: iTunes was not installed correctly. Please reinstall iTunes. Error 7(Windows error 1114)
    I have removed iTunes serveral time and tried to reinstall many times and get the same results noted above.
    Can anyone help me? Thank you. EFS1

    Hello DrJMDDC,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    Removing and reinstalling iTunes and other software components for Windows Vista, Windows 7, or Windows 8
    http://support.apple.com/kb/ht1923
    1. Remove iTunes and related components from the Control Panel
    2. Verify iTunes and related components are completely uninstalled
    3. Reinstall iTunes and related components
    Best of luck,
    Mario

Maybe you are looking for

  • Static PAT problem on ASA 7.2

    Here are the relevant parts of my config: interface Vlan1 nameif inside security-level 100 ip address 172.18.67.1 255.255.255.0 interface Vlan2 nameif outside security-level 0 ip address 71.x.x.x 255.255.255.0 interface Ethernet0/0 switchport access

  • Log in error 400

    can someone please help me..error 400 when logging in...tried the fix and still nothing..i want to use the share option..

  • Foriegn Currency setup using the RIC code

    Hi Gurus,          How to configure the foreign currency set up using the Reportable item code(RIC).We need to configure the D rate.and update the daily exchange rate through Reuters using the excel sheet.What is configuration required in sap Regards

  • I can't open Safari anymore!!

    i can't open Safari anymore. It keeps crashing each time I try. it says Safari quit unexpectedly here are the details, please help. Process:               Safari [634] Path:                  /Applications/Safari.app/Contents/MacOS/Safari Identifier: 

  • Error message the update" java for Mac OS X10.5 Update 4" can't be installe

    today i tried to installed the new update. I getting the error message the update" java for Mac OS X10.5 Update 4" can't be installed. Is anyone else getting this error? What do I do to get it installed? Austin