Can anybody help me with this code in my Xamarin project. I am trying to set a loading wheel (to signify that an action is happening and to let the user know to wait) when the "Login" button is clicked. For some reason since the function is asynchronous the loading wheel is never set to visible when the API code is run. It just fails to show up when I click login, however, it still does the login function.
// Defined up above in the file
var loginButton = new Button
{
Text = "Login",
};
loginButton.BackgroundColor = Color.Navy;
loginButton.TextColor = Color.White;
loginButton.Clicked += OnLoginButtonClicked;
async void OnLoginButtonClicked(object sender, EventArgs e)
{
loadingWheel.IsVisible = true;
try
{
var restUrl = "*******";
var content = string.Empty;
using (var client = new HttpClient())
{
string body = "{\"UserName\":\"" + usernameEntry.Text + "\", \"Password\":\"" + passwordEntry.Text + "\"}";
var contentType = new StringContent(body, Encoding.UTF8, "application/json");
var result = client.PostAsync(restUrl, contentType).Result;
content = await result.Content.ReadAsStringAsync();
}
if (content.ToLower() != "false")
{
var menuPage = new MenuPage();
NavigationPage = new NavigationPage(new HomePage());
RootPage = new Views.MainPage();
RootPage.Master = menuPage;
RootPage.Detail = NavigationPage;
MainPage = RootPage;
}
else
{
messageLabel.Text = "Username or password incorrect. Please try again.";
passwordEntry.Text = string.Empty;
}
}
catch (Exception ex)
{
messageLabel.Text = "Please check the internet connection for the connectivity.";
}
}
If I comment out the entire try block then the loading wheel does show up. It just does not work with the code in there.
Can anybody help me solve this problem? Thanks.
I think you can try with BeginInvokeOnMainThread
Device.BeginInvokeOnMainThread (() => {
loadingWheel.IsVisible = true;
});
UPDATE
I have also create this REPO... it works without BeginInvodeOnMainThread
public class MyPage6 : ContentPage
{
ActivityIndicator _ac = new ActivityIndicator { IsVisible = false, IsRunning = false };
public MyPage6()
{
Button b = new Button {Text = "Press for ActivityIndicator" };
b.Clicked += B_Clicked;
Content = new StackLayout
{
Children = {
_ac,
b,
new Label { Text = "Hello ContentPage" }
}
};
}
async void B_Clicked(object sender, EventArgs e)
{
_ac.IsRunning = true;
_ac.IsVisible = true;
await Task.Delay(2000);
_ac.IsRunning = false;
_ac.IsVisible = false;
}
}
Related
I'm using the ZXing plugin to scan bar codes and I'm using a custom overlay to display information and make a button visible/invisible when I need to perform an action, which in this case is to set a flag and make the button invisible again.
In this code I set up the scanning plugin:
MyButton_Scan.Click += async (sender, e) =>
{
var selectedEvent = string.Format("{0}", MyEventsSpinner.GetItemAtPosition(MyEventsSpinner.SelectedItemPosition));
if (selectedEvent.ToUpper() != "SELECT EVENT")
{
MobileBarcodeScanner.Initialize(Application);
scanner = new MobileBarcodeScanner();
scanner.UseCustomOverlay = true;
zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.scanner, null);
MyScanScreenButton = zxingOverlay.FindViewById<Android.Widget.Button>(Resource.Id.okButton);
MyScanScreenButton.Click += btnOk_Click;
MyScanScreenButton.Visibility = Android.Views.ViewStates.Invisible;
scanner.CustomOverlay = zxingOverlay;
var opt = new MobileBarcodeScanningOptions();
opt.DelayBetweenContinuousScans = 5000;
//Start scanning
scanner.ScanContinuously(this, opt, HandleScanResult);
} else
{
Utils.showMessage("Please select an event from the drop down list");
}
};
The code that handles the scan result and button click:
void btnOk_Click(object sender, System.EventArgs e)
{
popUpOpen = false;
MyScanScreenButton.Visibility = Android.Views.ViewStates.Invisible;
}
void HandleScanResult(ZXing.Result result)
{
if (!popUpOpen)
{
Boolean ConversionGood = true;
TextView MyTextView = zxingOverlay.FindViewById<TextView>(Resource.Id.ticketInfo);
Int32 convertedResult = 0;
Stream successbeepStream = GetType().Assembly.GetManifestResourceStream("eTicket_Scanner.beep.wav");
Stream failbeepStream = GetType().Assembly.GetManifestResourceStream("eTicket_Scanner.buzzer.wav");
MyTextView.SetBackgroundColor(Color.White);
try
{
convertedResult = Convert.ToInt32(result.Text);
}
catch (Exception ex)
{
ConversionGood = false;
bool isSuccess = _simpleAudioPlayer.Load(failbeepStream);
_simpleAudioPlayer.Play();
popUpOpen = true;
MyScanScreenButton.Visibility = Android.Views.ViewStates.Visible;
MyTextView.SetBackgroundColor(Color.Red );
MyTextView.Text = "Not a valid ticket for this event.\nErrorif applicable): " + ex.Message;
}
string scanResult = "";
if (ConversionGood)
{
scanResult = MyEventsService.VerifyScannedCode(MyUser.Username, MyUser.Password, currentEventID, convertedResult);
if (scanResult == "Y")
{
MyTextView.SetBackgroundColor(Color.Green);
bool isSuccess = _simpleAudioPlayer.Load(successbeepStream);
popUpOpen = true;
MyTextView.SetBackgroundColor(Color.Green);
MyTextView.Text = MyEventsService.GetTicketInfo(MyUser.Username, MyUser.Password, currentEventID, convertedResult);
_simpleAudioPlayer.Play();
MyScanScreenButton.Visibility = Android.Views.ViewStates.Visible;
}
else
{
bool isSuccess = _simpleAudioPlayer.Load(failbeepStream);
popUpOpen = true;
MyTextView.SetBackgroundColor(Color.Red);
MyTextView.Text = MyEventsService.GetFailedScanTicketInfo(MyUser.Username, MyUser.Password, currentEventID, convertedResult);
_simpleAudioPlayer.Play();
MyScanScreenButton.Visibility = Android.Views.ViewStates.Visible;
}
}
}
}
Its not a very complicated app, scan barcodes and verify the code, set the color of the textview background and display the info. The "Ok" button is never visible, but if I click in the space where the button should appear, it executes the button click code. I'm assuming that there is some sort of thread issue here with the interface, but anything I've tried with the thread hasn't worked. Anyone have any ideas?
I am having an issue with my code to add button from json where the first attempt i click add button, the menuflyout won't have any respond but second click attempt then it will work properly.
Can advise did i do anything wrong? Thanks.
private async void AddButton_Click(object sender, RoutedEventArgs e)
{
List<ClientList> clientLists;
var jsonSerializer = new DataContractJsonSerializer(typeof(List<ClientList>));
var myStream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(CLIENTSLIST);
clientLists = (List<ClientList>)jsonSerializer.ReadObject(myStream);
var menuFlyout = new MenuFlyout();
int isEmpty = myGrid.Children.Count;
if (isEmpty == 0)
{
foreach (var device in clientLists)
{
var menuFlyoutItem = new MenuFlyoutItem() { Name = device.clientname, Text = device.clientname };
menuFlyoutItem.Tag = device.clientaddress;
menuFlyoutItem.Click += AddMenuFlyoutItem_Click;
menuFlyout.Items.Add(menuFlyoutItem);
}
}else
{
foreach (var device in clientLists)
{
bool toAddButton = true;
foreach (Button btn in myGrid.Children.OfType<Button>())
{
if (btn.Content.ToString() == device.clientname)
{
toAddButton = false;
}
}
if (toAddButton)
{
var menuFlyoutItem = new MenuFlyoutItem() { Name = device.clientname, Text = device.clientname };
menuFlyoutItem.Tag = device.clientaddress;
menuFlyoutItem.Click += AddMenuFlyoutItem_Click;
menuFlyout.Items.Add(menuFlyoutItem);
}
}
}
AddButton.Flyout = menuFlyout;
}
The problem is you are loading the data asynchronously here:
var myStream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(CLIENTSLIST);
When this happens, UI continues executing the Click event, so the button is clicked (and Flyout is null the first time) and Flyout will never display. You should rather load the Flyout before that - either when the page loads or when the data source changes, so that when the user clicks, the flyout is already there. Doing loading in Click is simply too late, if you need an asynchronous operation to finish.
Alternatively you could set the flyout right at the start:
private async void AddButton_Click(object sender, RoutedEventArgs e)
{
var menuFlyout = new MenuFlyout();
AddButton.Flyout = menuFlyout;
List<ClientList> clientLists;
var jsonSerializer = new DataContractJsonSerializer(typeof(List<ClientList>));
var myStream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(CLIENTSLIST);
clientLists = (List<ClientList>)jsonSerializer.ReadObject(myStream);
int isEmpty = myGrid.Children.Count;
if (isEmpty == 0)
{
foreach (var device in clientLists)
{
var menuFlyoutItem = new MenuFlyoutItem() { Name = device.clientname, Text = device.clientname };
menuFlyoutItem.Tag = device.clientaddress;
menuFlyoutItem.Click += AddMenuFlyoutItem_Click;
menuFlyout.Items.Add(menuFlyoutItem);
}
}else
{
foreach (var device in clientLists)
{
bool toAddButton = true;
foreach (Button btn in myGrid.Children.OfType<Button>())
{
if (btn.Content.ToString() == device.clientname)
{
toAddButton = false;
}
}
if (toAddButton)
{
var menuFlyoutItem = new MenuFlyoutItem() { Name = device.clientname, Text = device.clientname };
menuFlyoutItem.Tag = device.clientaddress;
menuFlyoutItem.Click += AddMenuFlyoutItem_Click;
menuFlyout.Items.Add(menuFlyoutItem);
}
}
}
}
This way, the flyout will appear, but will be empty until the asynchronous loading finishes and the items are actually added. Here you are just reading a file, so it should be barely noticeable. Although not as clean as pre-loading the flyout, it should get the job done too.
I have a simple client registration form. I placed some textboxes next to a data grid view, so that I could add and update users. That was working fine and still does.
Recently, I have added a new windows form for client definition, so that when double-clicking a row a form with required field comes up that shows clients information and lets you change them. Clicking the "OK" button will save changes to the SQL database.
With the field beside the grid view, when I update a user info the grid view immediately gets updated and shows data, but when updating data with the new form, updates do not show in the grid view even if I double-click the row again. When I close the app and run it again I will see the updated data.
I have added an activation event for the main form to update the grid view with selecting data again from the database, but no success. This is the code that i am using for the update from side panel:
private void btnUpdate_Click(object sender, EventArgs e)
{
if (btnUpdate.Text == "Update")
{
txtUsername.Text = ClientsGridView.CurrentRow.Cells["Username"].Value.ToString();
txtPassword.Text = ClientsGridView.CurrentRow.Cells["Password"].Value.ToString();
txtUID.Text = ClientsGridView.CurrentRow.Cells["UID"].Value.ToString();
txtName.Text = ClientsGridView.CurrentRow.Cells["Name"].Value.ToString();
chkIsActive.Checked = (bool)ClientsGridView.CurrentRow.Cells["IsActive"].Value;
chkItemListAccess.Checked = (bool)ClientsGridView.CurrentRow.Cells["ItemListAccess"].Value;
chkMaterialSumAccess.Checked = (bool)ClientsGridView.CurrentRow.Cells["MaterialSumAccess"].Value;
chkPartListAccess.Checked = (bool)ClientsGridView.CurrentRow.Cells["PartListAccess"].Value;
chkPriceListAccess.Checked = (bool)ClientsGridView.CurrentRow.Cells["PriceListAccess"].Value;
btnUpdate.Text = "Apply Update";
btnSubmit.Enabled = false;
txtUsername.ReadOnly = true;
}
else if (btnUpdate.Text == "Apply Update")
{
if (ClientFormValidation())
{
int id = Convert.ToInt32(ClientsGridView.CurrentRow.Cells["ID"].Value.ToString());
var SelectedUser = from Client in ClientsContext.Clients
where Client.ID == id
select Client;
if (SelectedUser.Count() == 1)
{
Client UpdatingClient = SelectedUser.Single();
UpdatingClient.Password = txtPassword.Text.Trim();
UpdatingClient.UID = txtUID.Text.Trim();
UpdatingClient.Name = txtName.Text.Trim();
UpdatingClient.IsActive = chkIsActive.Checked;
UpdatingClient.ItemListAccess = chkItemListAccess.Checked;
UpdatingClient.MaterialSumAccess = chkMaterialSumAccess.Checked;
UpdatingClient.PartListAccess = chkPartListAccess.Checked;
UpdatingClient.PriceListAccess = chkPriceListAccess.Checked;
ClientsContext.SubmitChanges();
}
ShowAll();
ClearClientForm();
btnUpdate.Text = "Update";
btnSubmit.Enabled = true;
txtUsername.ReadOnly = false;
}
}
}
and this is for Client definition form:
private void btnOK_Click(object sender, EventArgs e)
{
if(ISnewUser)
{
InsertNewClient();
}
else if(!ISnewUser)
{
UpdateClient();
}
this.Close();
}
private void UpdateClient()
{
if (ClientFormValidation())
{
var SelectedUser = from Client in ClientsContext.Clients
where Client.ID == id
select Client;
if (SelectedUser.Count() == 1)
{
Client UpdatingClient = SelectedUser.Single();
UpdatingClient.Password = txtPassword.Text.Trim();
UpdatingClient.UID = txtUID.Text.Trim();
UpdatingClient.Name = txtName.Text.Trim();
UpdatingClient.IsActive = chkUserActiveSatus.Checked;
UpdatingClient.ItemListAccess = chkItemListAccess.Checked;
UpdatingClient.MaterialSumAccess = chkMaterialSummeryAccess.Checked;
UpdatingClient.PartListAccess = chkPartListAccess.Checked;
UpdatingClient.PriceListAccess = chkPriceListAcess.Checked;
ClientsContext.SubmitChanges();
}
}
}
Can anyone tell me what is wrong with this code?
*var SelectedUser = from Client in ClientsContext.Clients
where Client.ID == id
select Client;
It is Iqueryable, apply .ToList() to fetch into memory and then patch the change.
Instead i suggest , use this,
var SelectedUser = (from Client in ClientsContext.Clients
where Client.ID == id
select Client).FirstOrDefault();
if(SelectedUser!=null){
SelectedUser.Password = txtPassword.Text.Trim();
SelectedUser.UID = txtUID.Text.Trim();
SelectedUser.Name = txtName.Text.Trim();
SelectedUser.IsActive = chkUserActiveSatus.Checked;
SelectedUser.ItemListAccess = chkItemListAccess.Checked;
SelectedUser.MaterialSumAccess = chkMaterialSummeryAccess.Checked;
SelectedUser.PartListAccess = chkPartListAccess.Checked;
SelectedUser.PriceListAccess = chkPriceListAcess.Checked;
ClientsContext.SubmitChanges();
}
else{
//write your logic
}*
I am leaving exception handling to you only.
i solved it myself,
i passed a Client object while initializing the client definition form.
so for updating i used exactly the same object not getting its parapeter and selecting it again from data base:
public frmClientDefinition(Client thisClient=null)
{
InitializeComponent();
if (thisClient!=null)
{
User = thisClient;
id = thisClient.ID;
ISnewUser = false;
txtName.Text = thisClient.Name;
txtUsername.Text = thisClient.Username;
txtPassword.Text = thisClient.Password;
txtDate.Text = thisClient.Date.ToString();
txtUID.Text = thisClient.UID;
chkUserActiveSatus.Checked = thisClient.IsActive;
chkItemListAccess.Checked = thisClient.ItemListAccess;
chkPartListAccess.Checked = thisClient.PartListAccess;
chkMaterialSummeryAccess.Checked = thisClient.MaterialSumAccess;
chkPriceListAcess.Checked = thisClient.PriceListAccess;
chkFullPriceListAccess.Checked = false;
chkOfficialRecieptAccess.Checked = false;
chkNonOfficialRecieptAccess.Checked = false;
chkAdvancedPriceControlsAccess.Checked = false;
chkFullPriceListSaveAccess.Checked = false;
chkOfficialRecieptSaveAccess.Checked = false;
chkNonOfficialRecieptSaveAccess.Checked = false;
txtUsername.ReadOnly = true;
}
txtDate.Text = DateTime.Now.ToString();
}
and for updating this snippet:
private void UpdateClient()
{
if (ClientFormValidation())
{
User.Password = txtPassword.Text.Trim();
User.UID = txtUID.Text.Trim();
User.Name = txtName.Text.Trim();
User.IsActive = chkUserActiveSatus.Checked;
User.ItemListAccess = chkItemListAccess.Checked;
User.MaterialSumAccess = chkMaterialSummeryAccess.Checked;
User.PartListAccess = chkPartListAccess.Checked;
User.PriceListAccess = chkPriceListAcess.Checked;
ClientsContext.SubmitChanges();
}
}
I am using ZXing.Net camera barcode scanner, xamarin forms, and C# and it appears to be working good. But I have an issue where if I go the the next page via Navigation.PushAsync(), then click the Back Navigation Button, the ZXingScannerPage camera will not reload...(it will only be a still image of the last pic taken)...how do I reload the ZXingScannerPage so that the camera is actively upon pressing the Back Navigation? Is the anyway to refresh the camera view attached to the page?
Use the following code. Stop the scanning as soon as scanning is done. Don't do a manual manuver.
Entry objScanner= new Entry();
objScanner.Placeholder = "Barcode";
objScanner.Keyboard = Keyboard.Numeric;
objScanner.HorizontalOptions = LayoutOptions.StartAndExpand;
objScanner.WidthRequest = Application.Current.MainPage.Width - 40;
objScanner.SetBinding(Entry.TextProperty, "ElementValue", BindingMode.TwoWay);
objScanner.BindingContext = control;
layout.Children.Add(objScanner);
objScanner.Focused += async (s, e) =>
{
var scanPage = new ZXingScannerPage();
await Navigation.PushAsync(scanPage);
scanPage.OnScanResult += (result) =>
{
// Stop scanning
scanPage.IsScanning = false;
// Pop the page and show the result
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopAsync();
objScanner.Text = result.Text;
// await DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
};
The solution that I found that works for me to allow back navigation using ZXing Scanner page is to remove all instances of ZXing Scanner page before push a new instance of the page to the navigation stack. In your navigation.cs, when you get ready to push the page, use this:
foreach(var x in _navigation.Navigation.NavigationStack.ToList())
{
if((x.GetType() == typeof(/* name of your scanner page */)))
{
_navigation.Navigation.RemovePage(x);
}
}
var page = new /* your scanner page */();
_navigation.PushAsync( /* your scanner page */);
I have found a workaround which may be useful.
On content page, create a local content variable.
If I instantiate the scanner and add it to Content in OnAppearing method, then set Content = null OnDisappearing method. Nulling the Content seems to trigger the necessary cleanups up the stack.
Here's my code:
public class QrCodeScanPage : ZXingScannerPage
{
View _content;
public QrCodeScanPage()
{
InitScanner();
}
void InitScanner()
{
IsAnalyzing = true;
IsScanning = true;
DefaultOverlayTopText = "Align the barcode within the frame";
DefaultOverlayBottomText = string.Empty;
OnScanResult += ScanPage_OnScanResult;
Title = "Scan Code";
var item = new ToolbarItem
{
Text = "Cancel",
Command = new Command(async () =>
{
IsScanning = false;
await Navigation.PopAsync();
})
};
if (Device.RuntimePlatform != Device.iOS)
item.IconImageSource = "toolbar_close.png";
ToolbarItems.Add(item);
}
void ScanPage_OnScanResult(ZXing.Result result)
{
Device.BeginInvokeOnMainThread(async () =>
{
IsScanning = false;
IsAnalyzing = false;
await Navigation.PushAsync(new QrCodeScanResultPage());
});
}
protected override void OnAppearing()
{
IsScanning = true;
IsAnalyzing = true;
base.OnAppearing();
if (Content != null)
{
_content = Content;
}
if (Content == null)
{
Content = _content;
}
}
protected override void OnDisappearing()
{
base.OnDisappearing();
Content = null;
}
}
I am trying to develop a Windows Phone 7 application using Facebook login and logout operations. I found Facebook SDK and used it in order to carry out login, by opening WebBrowser. The user enters credentials to this browser and logs in successfully. Moreover, I managed to login the user without using any SDK, just using http requests, like the SDK actually does. However, I want to logout users without using any WebBrowser, but just clicking a button for example. There are so many solutions in the web suggesting that I should open web browser and navigate it to a certain URL in order to logout. However, this is not what I want. I think there should be a way to logout by clearing cookies, which I dont exactly know how to do, or any other that you suggest. Some part of my code below:
private static String appID = "";
private static String appSecret = "";
public static void login(String[] permissions)
{
try
{
permissionArray = permissions;
popup = new Popup();
popup.Height = 480;
popup.Width = 480;
popup.VerticalOffset = 100;
FacebookLoginUserControl control = new FacebookLoginUserControl();
control.facebookWebBrowser.Loaded += new RoutedEventHandler(webBrowser_Loaded);
control.facebookWebBrowser.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(webBrowser_Navigated);
popup.Child = control;
popup.IsOpen = true;
}
catch (Exception e)
{
//handle
}
}
private static void webBrowser_Loaded(Object sender, RoutedEventArgs e)
{
WebBrowser wb = (WebBrowser)sender;
String loginUrl = GetFacebookLoginUrl();
wb.Navigate(new Uri(loginUrl));
}
private static String GetFacebookLoginUrl()
{
String permissionString = String.Empty;
if (permissionArray.Length > 0)
permissionString = String.Join(",", permissionArray);
var uriParams = new Dictionary<string, string>() {
{"client_id", appID},
{"response_type", "token"},
{"scope", permissionString},
{"redirect_uri", "http://www.facebook.com/connect/login_success.html"},
{"display", "touch"}
};
StringBuilder urlBuilder = new StringBuilder();
foreach (var current in uriParams)
{
if (urlBuilder.Length > 0)
{
urlBuilder.Append("&");
}
var encoded = HttpUtility.UrlEncode(current.Value);
urlBuilder.AppendFormat("{0}={1}", current.Key, encoded);
}
var loginUrl = "http://www.facebook.com/dialog/oauth?" + urlBuilder.ToString();
return loginUrl;
}
private static void webBrowser_Navigated(Object sender, System.Windows.Navigation.NavigationEventArgs e)
{
if (string.IsNullOrEmpty(e.Uri.Fragment)) return;
if (e.Uri.AbsoluteUri.Replace(e.Uri.Fragment, "") == "http://www.facebook.com/connect/login_success.html")
{
string text = HttpUtility.HtmlDecode(e.Uri.Fragment).TrimStart('#');
var pairs = text.Split('&');
foreach (var pair in pairs)
{
var kvp = pair.Split('=');
if (kvp.Length == 2)
{
if (kvp[0] == "access_token")
{
accessToken = kvp[1];
MessageBox.Show("Access granted");
RequestUserProfile();
}
}
}
if (string.IsNullOrEmpty(accessToken))
{
MessageBox.Show("Unable to authenticate");
}
popup.IsOpen = false;
}
}
private static void RequestUserProfile()
{
var profileUrl = string.Format("https://graph.facebook.com/me?access_token={0}", HttpUtility.UrlEncode(accessToken));
request = (HttpWebRequest)HttpWebRequest.Create(new Uri(profileUrl));
request.Method = "GET";
request.BeginGetResponse(result =>
{
try
{
var resp = (result.AsyncState as HttpWebRequest).EndGetResponse(result);
using (var strm = resp.GetResponseStream())
{
StreamReader sr = new StreamReader(strm);
var responseString = sr.ReadToEnd();
}
}
catch (Exception ex)
{
//
}
}, request);
}
Any Ideas to solve the problem.
Thanks in advance
What's actually so spooky in using webBrowser? If you programmatically create a WebBrowser object, it won't be visible, unless you'd add it somewhere on form/page. If you want to clear cookies for Facebook, the solution will be something like that:
// Can be invoked from your button_click event
public void TryLogout()
{
webBrowser = new WebBrowser();
Uri uri = new Uri("http://m.facebook.com/home.php?r", UriKind.Absolute);
webBrowser.LoadCompleted += new LoadCompletedEventHandler(webBrowser_TryLogoutLoadCompleted);
webBrowser.Navigate(uri);
}
And then:
private void webBrowser_TryLogoutLoadCompleted(object sender, EventArgs e)
{
try
{
var cookies = webBrowser.GetCookies();
foreach (Cookie cookie in cookies)
{
if (cookie.Domain.Contains("m.facebook.com"))
{
cookie.Discard = true;
cookie.Expired = true;
}
}
// we've just cleaned up cookies
}
finally
{
webBrowser.LoadCompleted -= webBrowser_TryLogoutLoadCompleted;
}
}
Hope this helps.
GetCookies method