This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public bool DeepLogin() | |
{ | |
bool login = false;//ログイン成否 | |
HttpWebRequest req = WebRequest.CreateHttp(new Uri(deepLoginUrl, UriKind.Absolute)); | |
req.Method = "POST"; | |
req.ContentType = "application/x-www-form-urlencoded"; | |
req.CookieContainer = App.ViewModel.UserSetting.cc; | |
using (StreamWriter sw = new StreamWriter(req.GetRequestStreamAsync().GetAwaiter().GetResult())) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ライブラリ側のコード | |
public class DeadlockSample | |
{ | |
public static async Task DoAsync() | |
{ | |
//規定のawaitだとライブラリユーザにWaitされた場合デッドロックになる可能性がある | |
await HeavyWorkAsync(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ライブラリ側のコード | |
public static async Task DoAsync() | |
{ | |
//デッドロックを回避するにはConfigureAwait(false)メソッドを呼び出す | |
await HeavyWorkAsync().ConfigureAwait(false); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// GUIアプリケーションのコードビハインド | |
/// </summary> | |
public sealed partial class MainPage : Page | |
{ | |
public MainPage() | |
{ | |
this.InitializeComponent(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AsyncClass | |
{ | |
//この通知によってライブラリユーザはGUIを更新することが高いと予想される | |
public event Action SomeEventHandler; | |
public async Task DoAsync() | |
{ | |
//ここまでGUIスレッドで実行されているとする | |
//.ConfigureAwait(false)でUIスレッドに戻さない |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AsyncClass | |
{ | |
//この通知によってライブラリユーザはUIを更新することが高いと予想される | |
public event Action SomeEventHandler; | |
public async Task DoAsync() | |
{ | |
//ここまでUIスレッドで実行されているとする | |
//UIスレッドの同期コンテキストをキャッシュする |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async void Button_Click_1(object sender, RoutedEventArgs e) | |
{ | |
//ConfigureAwait(false)でUIスレッドに戻さない | |
await Task.Delay(5).ConfigureAwait(false); | |
var asyncObject = new AsyncClass(); | |
asyncObject.SomeEventHandler += async()=> | |
{ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Foo(int x) | |
requires Range.IsValid(x, ...) | |
{ | |
.... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Foo(int x) | |
{ | |
if (!Range.IsValid(x, ...)) | |
throw new ArgumentOutOfRangeException("x"); | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
・Xamarin.FormsのUWP版ListViewだと仮想化が有効にならない | |
UWPの仕様上常にListViewは仮想表示されることになっているが、実際には仮想化されず追加したぶんだけListViewItemが生成される。 | |
原因について恐らくではあるが、Xamarin.FormsのUWP版ListViewの実装でUWPのListViewItemのMinHeightを0に設定されているのが原因。 | |
UWPの挙動として、ListViewItemの高さを算出できなかった時にMinheightをもとに仮想表示に必要な高さを求めるようになっているらしく、 | |
仮に1万個追加されたとしてもMinHeightが0だと高さ0のItemが追加されたとみなされるため全て表示しようとする。そのためListViewItemが大量に生成される。 | |
この現象はXamarin.FormsのDatatemplate内のHeightRequestを設定してもなぜか解決しなかった。 | |
この現象を解決するにはUWPのプロジェクト内にあるAppクラスのリソースにFormsListViewItemをKeyとしたStyleリソースにMinHeightに0以外の数値を設定するSetterを定義するか、 | |
もしくはMinHeightのSetterを定義しないことで解決する。(MinHeightは規定値の場合0になるがなぜかListViewItemは大量に生成されない) | |
ただし、この行為は元々Xamarin.FormsにあるFormsListViewItemリソースを上書きする行為なので、注意すること。 |
OlderNewer