Hello:
I can use the repo to upload one MP4 file in a console app.
The following is my C# code: (.Net 4.8 framework)
static int Main(string[] args)
{
string MP4_File_Name = args[0];
if (!File.Exists(MP4_File_Name))
return (-1);
string show_upload1 = string.Format("Upload time=[{0}], upload file is:", DateTime.Now.ToLocalTime());
Console.WriteLine(show_upload1);
Console.WriteLine(MP4_File_Name);
Engine engine = new Engine();
engine.Sleep(5000);
var window =
engine.GetDesktopPane().Pane("Upload | TikTok - Google Chrome");
window.Highlight();
window.ClickAt(207, 655);
var combo = engine.GetDesktopPane()
.Pane("Upload | TikTok - Google Chrome").Window("Open").ComboBox("File name:");
combo.Highlight();
combo.SetText(MP4_File_Name);
var openBtn =
engine.GetDesktopPane().Pane("Upload | TikTok - Google Chrome").Window("Open").Button("Open");
openBtn.Highlight();
openBtn.Press();
engine.Sleep(30000);
engine.GetDesktopPane().Pane("Upload | TikTok - Google Chrome").ClickAt(643, 852);
engine.Sleep(10000);
engine.GetDesktopPane().Pane("Upload | TikTok - Google Chrome").ClickAt(470, 630);
engine.Sleep(5000);
return 0;
}
When I run this alone, it works.
However, I have a lot of MP4 files to upload, so I had another WinForms app project, in which I call the program with necessary parameter (the file name) in a loop through all the MP4 files.
The following is my C# code: (.Net 6.0 on Windows 10)
public static async Task TikTok_Upload_MP4_File1(string mp4_file1)
{
int return_code1 = 0;
try
{
Process process = new()
{
StartInfo = new ProcessStartInfo
{
FileName = TikTok_Upload_CLI,
Arguments = mp4_file1,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
},
EnableRaisingEvents = true
};
process.Start();
string output = process.StandardOutput.ReadToEnd();
bool has_return_code =
int.TryParse(output, out int return_code);
if (has_return_code)
return_code1 = return_code;
process.WaitForExit();
await Task.Delay(3000);
}
catch (NullReferenceException ex)
{
Debug.Print("[TikTok_Upload_MP4_File1]" + ex.Message);
}
return return_code1;
}
When I run the above code, it simply times out, there is no error. But the code didn’t run. (FileName = TikTok_Upload_CLI => this is the binary for the console app.)
Please advise on how I can integrate the console app in my WinForms app project.
Thanks,