完善主體資料,免費贈送VIP會員!
      * 主體類型
      * 企業名稱
      * 信用代碼
      * 所在行業
      * 企業規模
      * 所在職位
      * 姓名
      * 所在行業
      * 學歷
      * 工作性質
      請先選擇行業
      您還可以選擇以下福利:
      行業福利,領完即止!

      下載app免費領取會員

      NULL

      ad.jpg

      二次開發教程:Revit開發之多線程

      發布于:2019-08-23 17:05:28

      網友投稿

      更多

      關于Revit開發其實是可以使用多線程的,但是是有限制的,目前發現只要在其他線程里啟用Transaction,基本Revit就崩潰了,


      但是在其他線程里不啟用Transaction還是可以使用的,比如說我們要在Revit里檢索一些東西,但這些東西又很多,需要的時間


      比較長,這種情況我們就可以把檢索的任務給其他線程,然后用戶先可以先進行其他操作,


      下面說一個簡單的例子,在Task里檢索建筑柱的數量,然后顯示到Window里,但是檢索數量的時候,用戶可以在Window里進行


      其他數據的輸入:




      namespace MultiThreading

      {

          [Transaction(TransactionMode.Manual)]

          public class Class1:IExternalCommand

          {

              public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)

              {

                  Document doc = commandData.Application.ActiveUIDocument.Document;

                  ViewModel vm = new ViewModel(doc);

                  if (vm.ShowWindow() ?? false)

                  { 

                      

                  }

                  return Result.Succeeded;

              }

          }



          public class ViewModel:ViewModelBase

          {

              public MainWindow win = null;

              public ViewModel(Document doc)

              {

                  Task task = new Task(() =>

                  {

                      Thread.Sleep(10000);//由于檢索太快,所以讓Task等待10秒

                      FilteredElementCollector temc = new FilteredElementCollector(doc);

                      temc.OfCategory(BuiltInCategory.OST_Columns).OfClass(typeof(FamilyInstance));

                      I = temc.Count();

                      CanExecute = true;

                  });

                  task.Start();

                  win = new MainWindow();

                  win.DataContext = this;

              }



              private bool canExecute = false;

              public bool CanExecute

              {

                  get

                  {

                      return canExecute;

                  }

                  set

                  {

                      canExecute = value;

                      base.RaisePropertyChanged(() => CanExecute);

                      base.RaisePropertyChanged(() => OK_Command);

                  }

              }



              private int? i = null;

              public int? I

              {

                  get

                  {

                      return i;

                  }

                  set

                  {

                      i = value;

                      base.RaisePropertyChanged(() => I);

                  }

              }

              public ICommand OK_Command

              {

                  get

                  {

                      return new RelayCommand(() => {

                          win.DialogResult = true;

                          win.Close();

                      },()=>CanExecute);

                  }

              }

              public ICommand Cancel_Command

              {

                  get

                  {

                      return new RelayCommand(() =>

                      {

                          win.DialogResult = false;

                          win.Close();

                      });

                  }

              }

              public bool? ShowWindow()

              {

                  return win.ShowDialog();

              }

          }

      }




      <Window x:Class="MultiThreading.MainWindow"

              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

              Title="MainWindow" Height="300" Width="300">

          <Grid>

              <Label Content="柱子的數量為:" HorizontalAlignment="Left" Margin="86,97,0,0" VerticalAlignment="Top"/>

              <Button Content="確定"  Command="{Binding Path=OK_Command}" HorizontalAlignment="Left" Margin="76,229,0,0" VerticalAlignment="Top" Width="75"/>

              <Button Content="取消" Command="{Binding Path=Cancel_Command}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="191,229,0,0"/>

              <TextBox HorizontalAlignment="Left" Height="23" Margin="180,101,-8,0" IsReadOnly="True" TextWrapping="Wrap" Text="{Binding Path=I,UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="120"/>

              <TextBox HorizontalAlignment="Left" Height="23" Margin="156,169,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>

              <Label Content="其他輸入:" HorizontalAlignment="Left" Margin="86,165,0,0" VerticalAlignment="Top"/>

          </Grid>

      </Window>




          public partial class MainWindow : Window

          {

              public MainWindow()

              {

                  InitializeComponent();

              }

          }

      本文版權歸腿腿教學網及原創作者所有,未經授權,謝絕轉載。

      未標題-1.jpg

      上一篇:二次開發教程:WPF通過異常來驗證用戶輸入

      下一篇:二次開發教程:Revit開發將WPF的Ower設置為Revit窗體

      主站蜘蛛池模板: 国产在线视频一区| 无码夜色一区二区三区| 精品一区二区久久| 精品无人区一区二区三区| 国产成人精品亚洲一区| 一区二区在线视频| 精品国产一区二区三区AV性色| 日韩免费一区二区三区在线| 无码av免费一区二区三区| 国产在线不卡一区二区三区| 精品免费AV一区二区三区| 性无码免费一区二区三区在线| 国产伦精品一区二区三区视频猫咪 | 麻豆果冻传媒2021精品传媒一区下载| 中文字幕一区二区视频| 一区国严二区亚洲三区| 老湿机一区午夜精品免费福利| 国产福利酱国产一区二区| 亚洲Av永久无码精品一区二区| 亚洲中文字幕在线无码一区二区 | 亚洲av无码一区二区乱子伦as| 一区二区三区四区国产| 日韩精品一区二区三区中文字幕| 日韩精品电影一区| 日本一道一区二区免费看| 婷婷亚洲综合一区二区| 美女AV一区二区三区| 国产日韩精品一区二区在线观看 | 亚洲福利一区二区精品秒拍| 97av麻豆蜜桃一区二区| 麻豆一区二区免费播放网站| 午夜视频在线观看一区二区| 国产精品久久久久一区二区| 一区二区三区在线观看免费| 中文字幕一区精品| 亚洲欧洲精品一区二区三区| 精品一区二区ww| 国产成人综合精品一区| 国产日韩一区二区三区在线观看| 亚洲国产日韩一区高清在线| 日韩一区二区三区射精|