日々メモ 2021/07
  • My overview of WPF application architecture
    • View consists of multiple user controls.
    • You may use CustomControl for small and independent UI components.
    • Each Window or Control has its own ViewModel.
    • Do not bind ViewModel to UserControl. Let parent View bind it.
      • DataContext={binding SubVM}.
      • Doing so will make it easy to share models between 2 VMs.
      • If you want a closed and easy-to-use module, then its fine.
    • IValueConverter
    • ViewModel holds Model.
    • To update View from ViewModel, use NotifyPropertyChanged
    • To update ViewModel from Model, use event.
      • Event is best. It abstracts the data modification.
      • NotifyPropertyChanged in Model is OK, but I always try to avoid it.
  • How to share VM?
    • Set VM to MainWindow, let dataContext propagate through childs.
  • How to make styles consitent?
    • Use ResourceDictionary.
    • <ResourceDictionary>
          <MergedDictionary>
          <Style>
      
    • ResourceDictionary src="/path" often works OK when included from UserControl, but raises error when that UserControl is used from others.
      • cannot locate resource "/path/aaa.xaml"
      • use: `pack://application:,,,/AssemblyName;component/path/aaa.xaml"
      • clean, rebuild to fix error in designer.
    • prefer application.resource, not usercontrol.resource
      • ???
    • XAML describes layout structure. design styles comes next.
  • Multithreading
    • on user action, do not do heavy process on UI thread.
    • use Task/Thread to offload heavy jobs
    • use Dispatcher.BeginInvoke to update UI from NonUI thread
    • do not modify collection from worker thread
    • NotifyPropertyChanged might not be thread safe.
      • PropertyChanged.Invoke vs PropertyChanged.BeginInvoke
  • Networking
    • UDP Handling
      • you throw a ball. You expect 0 to N balls returned.
    • Handling
      • いつ来るかわからない => use multithread, do not wait and block.
      • 永遠に来ない => close, KeepAlive
      • 不完全なものが来る => Integrity and Discard.
      • こちらが受信できない => メモリ足りない? TCPWindow0
        • /proc/sys/net/ipv4/tcp_mem
      • Socket.Timeout => 別Taskにできるならいらない?でも完全に機能停止する可能性があるのでは。
  • Z階数曲線
  • ヒルベルト曲線
  • 曲線の数学
  • 同じ処理を2回実行しない技術